Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

How to make Git pull use rebase by default for all my repositories?

Is there a way to setup the host Git repository such that any git pull done from its (local) clones uses --rebase by default? By searching on Stack Overflow, I learned about branch.autosetuprebase, but it needs to be configured per clone individually.

My project flow is set up such that we pull the develop branch before mergeing a feature branch to it. This pull nearly always uses --rebase, so I am trying to figure out if this can be the default.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are now 3 different levels of configuration for default pull behaviour. From most general to most fine grained they are:

1. pull.rebase

Setting this to true means that git pull is always equivalent to git pull --rebase (unless branch.<branchname>.rebase is explicitly set to false). This can also be set per repository or globally.

2. branch.autosetuprebase

Setting this to always means that whenever a tracking branch is created, a configuration entry like the one below will be created for it. For finer grained control, this can also be set to never, local or remote and can be set per repository or globally. See git config --help for further details.

3. branch.<branchname>.rebase

Setting this to true means that that particular branch will always pull from its upstream via rebasing, unless git pull --no-rebase is used explicitly.

Conclusion

So while you can't change the default behaviour for all future clones of a repository, you can change the default for all of the current user's (existing and future) repositories via git config --global pull.rebase true.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...