At work, if I am working on a bug fix, I sometimes want to base my hotfix branch off of the merge-base of our master and develop branches, because the branch will eventually be merged into both of these branches, and sometimes, they (master and develop) will have diverged. From the command line I would do this with:

git checkout `git merge-base master develop`
git checkout -b my-hotfix-branch

What I am wondering is, is there a straightforward way to do this in magit?

I don't fully understand some of the options in the branching popup, even after reading the documentation, and I am hesitant to experiment with my work repository. I know how to do the second command (checkout a new branch once I have checked out the merge-base, but I am not sure how to check out the merge-base itself).

Worse comes to worse, I assume everything will go fine if I run the command from the magit-run-popup, but I am curious if there is a better way. Thank you!

  • Do you want to do that because the bug was introduced before the merge-base and you want to be able to merge the hotfix branch into both master and develop without having to merge one of these two branches into the other? – tarsius Dec 29 '15 at 15:34
  • @tarsius, potentially, yes. Usually this will be unnecessary, and it is enough for me to base my fix off of master or even develop, but I was told that I should just do it this way to be on the safe side so that I don't need to worry about what state master and develop are in. – elethan Dec 29 '15 at 15:39
  • But that of course assumes that the bug was introduced before the merge-base, so "to be on the safe side" doesn't really seem to apply. I think doing it as it was suggested to you only makes sense if you actually intend to merge into both branches. Otherwise you just branch of the hotfix at some essentially random commit. Branching of the commit that introduced the bug might make more sense. But that might have been a long time. – tarsius Dec 29 '15 at 15:45
  • I would suggest that you figure out upfront whether the hotfix has to be merged into both branches. If so, then branch of the merge-base (or possibly the commit which introduced the bug). Otherwise branch of master and then merge it back into that. If it later turn out that the fix is also needed in develop and you don't want to merge master to get it, then you could always just cherry-pick the fix. – tarsius Dec 29 '15 at 15:47

There isn't a direct way to do that. What I would do - assuming that both of these branches have at most a few dozen commits since the merge-base - is to manually move to the merge-base in some log and then type b chotfixRET. A good log to start from you would get with l b (assuming --graph is enabled), and then you have to press n a "few" times.

| improve this answer | |
  • @elethan is one of master or origin/master configured as develops upstream? If so, then it probably wouldn't be to hard to implement a generalized command to do this sort of thing (but I don't think it should be added to Magit). If develops upstream is origin/develop, then you should probably change that and instead set the push-remote to origin. – tarsius Dec 29 '15 at 16:01
  • My current situation is that I am a junior dev in a team of basically 2 people, and am not in a position to make any changes or even to propose changes to our current git workflow - nor, do I know enough at this point to really be able to choose between one approach or another. I was just curious if there was a quick way to go right to the merge-base of two branches through magit, since this is the way I was told to do it by team member #2 (who is basically my boss). I am trying not to be a squeaky wheel at this point :) – elethan Dec 29 '15 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.