git pull --rebase
you can set up your git config to always rebase when pulling. git config master.rebase true
sets it up for master of the current repo git config --global branch.autosetuprebase always
sets it up for all new branches. git pull --rebase
you can set up your git config to always rebase when pulling. git config master.rebase true
sets it up for master of the current repo git config --global branch.autosetuprebase always
sets it up for all new branches.This also helps when pairing with someone else. The process of handling a rebase conflict vs pull/merge (regular pull) is quite different.
Example: I am working on a local branch feature/xyz. I decide I am done my work and merge feature/xyz -> master. I get ready to push and realize I am 5 commits behind origin/master. How do I fetch them now?
If you use git --rebase it will clobber your feature branch merge commit. On the other hand if you do a fetch & merge this also probably is not what you want (you will have a merge-commit on top of your merge commit, dawg). git rebase -p is probably the best option in this scenario.
In this case, you have a merge commit from a branch on to master, which would look like:
A-B(master)----F (merge commit)
\ /
C-D-----E (topicA)
Once you find out your master (B) is behind, because say there's G-H-I on origin, you'd want to rebase onto that. So you use the 3-argument form of git rebase --onto:git rebase --onto origin/master C~1 E
Which would take C's old base, C~1 (B), and replace it with origin/master, but only up to E.
Or, if you still had the branch around that you merged into master (which you do, in many forms, including the reflog, even after you delete the branch).
git rebase --onto origin/master topicA
I wrote a blog post on the different uses of git rebase --onto: http://krishicks.com/blog/2012/05/28/git-rebase-onto/
I knew about git rebase -p and its nuances, but haven't known about the --onto until now. The 3-argument form of git rebase --onto in your blog post was great, thanks!
git reset --hard HEAD~1
git fetch;
git merge origin/master;
git push origin HEAD:master;
git push origin HEAD:old_branch;