4 ms·
Rather than always using git pull --rebase you can set up your git config to always rebase when pulling. git config master.rebase true sets it up for ma
by pwim 13y ago
Rather than always using
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.
- Osiris 13y agoI would argue that it's not a good idea to do this for all branches by default. For example, we do the opposite for 'master', we force merge commits (--no-ff) on master/integration branches but use pull --rebase on feature branches that we share.
- nahname 13y agoI 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.
- wanderr 13y agoautosetuprebase is annoying because it doesn't apply to any already existing branches, and because it's configuring a per-branch setting going forward, if you ever want to change the setting later after you have a lot of branches, you're going to be making a lot of config changes in a lot of places. Instead you can just do: git config --global pull.rebase true