← back to the blog


Git :: Make the current branch the master branch

Posted on April 28th, 2017 in git by Elijah

Sometimes you just get got by git.  Tonight I got got by git.  It was an hour of me remembering how last time I said I would never do this again.  But, here I was again trying to figure out how to get the myriad of branches I had all on a merged level playing field.  I have a master branch and an azure branch as well as a heroku branch.  I know.  I know.  Why do I have heroku and azure? Because I am in the middle of setting up azure and still hadn't taken the time to finish the process. So I have both.  Anyways, I fought for an hour with the command line and with SourceTree.  SourceTree is almost always my saving grace.  If they only had a better difference checker and a few easier ways to attach arguments to the basic commands.  Maybe they do, but they aren't in an obvious GUI location.  Anyways, I finally found the answer I was looking for in this StackOverflow question.

git checkout better_branch
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge better_branch             # fast-forward master up to the merge


From the command line you have so much more control if you need to make a major change.  I do love SourceTree for anything that Webstorm isn't handling with their Awesome VCS.  Hope this helps someone somewhere.