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

前端 未结 5 1605
礼貌的吻别
礼貌的吻别 2020-11-28 17:19

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

5条回答
  •  佛祖请我去吃肉
    2020-11-28 18:20

    Currently there is no way to set the default policy for a repository.

    If you want it for yourself and you use at least git 1.7.9, you can globally set the pull.rebase configuration as follow:

    git config --global pull.rebase true
    

    But you'll have to do on each machine. One option could be to configure the default user home template/skeleton with that option. Users might, however, change that option.

    If you don't want merges, you could define a server-side hook to reject pushes with merges.

    For your reference, his is the source documentation for pull.rebase:

    When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run. See "branch..rebase" for setting this on a per-branch basis.

    When merges, pass the --rebase-merges option to git rebase so that the local merge commits are included in the rebase (see git-rebase for details).

    When preserve, also pass --preserve-merges along to git rebase so that locally committed merge commits will not be flattened by running git pull.

    When the value is interactive, the rebase is run in interactive mode.

    NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git-rebase for details).

提交回复
热议问题