Simplify git the usual "swift cherry to another branch"

There are two branches in my repository: "stable" and "master". Sometimes I have to fix a bug in "stable" and "cherrypick" on "master". To do this, I have to go through a few steps: switch to "master", find the commit and cherrypick, then I have to go back to "stable" to fix the next error. How can I simplify this procedure? Is it possible?

+3


source to share


3 answers


If you can type it on the command line, you can script it:

git checkout master && git cherry-pick stable && git checkout stable 

      

Note: there git cherry-pick stable

will be cherry-picking commit in the TIP of the stable branch.

If you want a more general function:



#An alias so we can get the current branch with `git current-branch`
git config --global alias.current-branch 'symbolic-ref --short HEAD'

git-cherry-pick-onto() {
   local original_branch=`git current-branch`

   git checkout "$1" &&\
   git cherry-pick "$original_branch" &&\
   git checkout "$original_branch"
}

      

And then you can do (from stable):

git-cherry-pick-onto master

      

and this will hang the last commit on the current branch to master (or whatever branch you provide as an argument).

+1


source


Indeed, if your branches are very different from each other, re-checking on a different branch can be unbearable.

You can add a local copy of your repository and always follow the master branch , while the original repo always looks at the stable branch .



Everything you need in this scenario to switch between repositories.

+1


source


You can blacken multiple commits git cherry-pick 18795aedbc 5415dfeacb ...

, I suggest fixing your whole commit bug and cherry-picking all commits at the end.

0


source







All Articles