4 ms·
I would recommend that you do not do this. I rebase probably 80% of my pull requests, but sometimes you do want a merge commit. Instead, I setup an alias for gi
by nahname 13y ago
I would recommend that you do not do this. I rebase probably 80% of my pull requests, but sometimes you do want a merge commit. Instead, I setup an alias for git pull --rebase
This also helps when pairing with someone else. The process of handling a rebase conflict vs pull/merge (regular pull) is quite different.
- wanderr 13y agoif you want to do a merge commit sometimes, but pull --rebase most of the time, why not make pull --rebase the default, and do a fetch && merge when that's what you want?
- Zombieball 13y agoBecause what if you 'already' created a merge? 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.
- base698 13y agogit checkout -b branch_fix; # for safety git reset --hard HEAD~1 git fetch; git merge origin/master; git push origin HEAD:master; git push origin HEAD:old_branch;
- erso 13y agoI would ignore everything base698 says below. 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/ http://krishicks.com/blog/2012/05/28/git-rebase-onto/
- Zombieball 13y agoAh awesome, I love there are so many things to learn about git. 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!
- nahname 13y agoFor me, my alias 'git pr' is shorter than 'git pull'. For the person working with me, not being in a rebase when they didn't expect to be is also a boon.