How can I pull all remote changes with rebase instead of merge?

吃可爱长大的小学妹 提交于 2019-12-20 09:49:56

问题


I can pull changes using git pull, but it merges my local commits. Is there a git rebase equivalent with which I can pull in remote changes?


回答1:


Yes you can git pull --rebase.

You can also set that to be the default pull behaviour when you track a branch with git config branch.autosetuprebase always. Replace "always" with "remote" or "local" if you want to do it to those specific types of branches that you're tracking.

Now all you have to do is git pull.

If for some reason you want to do a merge, you can do git pull --no-rebase.

Hope this helps.

UPDATE: see comments below for how to do this on existing branches.




回答2:


Instead of autosetuprebase, you can use the pull.rebase config option to change the behavior for every git pull (instead of only newly-created branches):

[pull]
    rebase = true

The difference is this will apply to non-tracking branches and any branches you had set up before enabling autosetuprebase. So if you really want pull --rebase to always be the default, pull.rebase is the way to go!




回答3:


I usually use a fetch/rebase combination so my current (local) work stays at the top:

git fetch
git rebase origin/develop



回答4:


To change default behavior from merge to rebase In git >= 1.7.9:

git config --global pull.rebase true

remove global if you want to apply for current repo only



来源:https://stackoverflow.com/questions/5306031/how-can-i-pull-all-remote-changes-with-rebase-instead-of-merge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!