Merging to a branch in git without switching to it

Viewed 5600

I have an application running in a git repository on a branch (say dev). The application modifies the content in some the repository and commits them. I now have to merge these changes into another branch (say master) but the snag is that I don't want to git checkout master before doing this. Is there some way to say "merge current branch into master"?

4 Answers

Even if your branch isn't fast-forwardable and even if it has real conflicts, you can still merge without a full checkout. Say you want to merge your current tip dev into master. It's worth trying the git push . dev:master if you think it might work, that checks whether a fastforward is the right move and if so does it right there, but if you can't just re-hang the label your next step is

git clone -nsb master . `mktemp -d`
cd $_
git reset -q
git merge origin/dev
git push
cd -

and you have now done a "minimum-checkout merge". The clone, cd and reset takes less time to run than it takes to type on a not-small project (3.5G history, 1.2G full checkout is >70K files) on a ten-year-old midrange because it doesn't duplicate anything.

Related