When using Git, I often find myself doing the following when working in master:
# work work work...
$ git checkout -b temp
$ git commit -a -m 'more work done'
$ git checkout master
$ git pull origin master
# turns out master was updated since my previous pull
$ git checkout temp
# I don't want a merge commit for a simple bugfix
$ git rebase master
$ git checkout master
$ git merge temp
$ git push origin master
$ git branch -d temp
… and I get tired of doing this. Is there a way to do this dance without all of the checkouts, and preferably without (manually) creating the temporary branch?
If you don’t mind not creating a branch called
temp, you could just do the following all onmaster:… or equivalently:
If you do want to keep the
tempbranch, however, you can still make this a bit shorter by not checking outmasterjust to do thepull– you only need tofetchand then rebase your branch ontoorigin/master:sehe’s answer reminds me that you could replace:
… with:
… which is nearly equivalent. The difference is that when you run
git fetch origin, all of your remote-tracking branches fororiginwill be updated, whereas when you pull a particular branch fromorigin, none of them are – it’s just the temporary refFETCH_HEADthat is updated. I personally prefer running one extra command (git fetch origin), and seeing all the remote branches that have changed in the output.