简体   繁体   中英

git: how do I configure tracking a branch by merging and not by rebasing?

I want to setup a local tracking branch that will be tracking a remote branch by merge and not by rebase.
When I do git pull I want to merge from the remote branch, not to rebase.

When I do:

git checkout -b someBranch origin/someBranch

and then

git remote show origin

I see:

Local branches configured for 'git pull':
  someBranch rebases onto remote someBranch
Local refs configured for 'git push':
  someBranch pushes to someBranch (local out of date)

The same thing also happens if I do

git checkout --track origin/someBranch

Is this somehow configured locally?
How do I change this behaviour?

By default, GIT does merge during pulls. If yours is doing rebase, then it seems that at some point of time you had changed that behavior. Or someone helpful did that for you.

Citing after this article (1) and this article (2) and this article (3) - which all describe how to do the opposite thing:

(from 1) There is a configuration flag in GIT that, when enabled, changed the default behavior of pull from merge to rebase . Check if you have it set:

# git >= 1.7.9:
git config --global pull.rebase
git config pull.rebase

In newer GIT clients, it works intuitively. It is enabled if it's true . Just turn the flag off.

In older however, it works differently.

# git < 1.7.9:
git config --global branch.autosetuprebase
git config branch.autosetuprebase

# and also
git config branch.<name>.rebase

When autosetuprebase is set to always , git automatically sets rebase flag on each new branch. This means that only you will probably want to not only disable autosetuprebase , but also to turn off the already-set rebase flag for each branch.

(from #2)
If you want another way (ie you've got old GIT client and tons of branches and you actually do mind writing a script that resets the flags) then another option is to create an alias for git pull that will add --no-rebase option, what will force it to do a merge.

(from #3)
This article says that the per-branch rebase flag is kept in a config file. So, after turning autosetuprebase off, it seems you can quickly disable rebaseing on all or some branches by remove all rebase lines from that config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM