Automatic prune with Git fetch or pull

后端 未结 3 1825
我在风中等你
我在风中等你 2020-11-27 09:29

If someone deleted a remote branch because the work is over and I don\'t know, I won\'t do a git fetch --prune and eventually I will push back the deleted branc

3条回答
  •  渐次进展
    2020-11-27 10:05

    Since git 1.8.5 (Q4 2013):

    "git fetch" (hence "git pull" as well) learned to check "fetch.prune" and "remote.*.prune" configuration variables and to behave as if the "--prune" command line option was given.

    That means that, if you set remote.origin.prune to true:

    git config remote.origin.prune true
    

    Any git fetch or git pull will automatically prune.

    Note: Git 2.12 (Q1 2017) will fix a bug related to this configuration, which would make git remote rename misbehave.
    See "How do I rename a git remote?".


    See more at commit 737c5a9:

    Without "git fetch --prune", remote-tracking branches for a branch the other side already has removed will stay forever.
    Some people want to always run "git fetch --prune".

    To accommodate users who want to either prune always or when fetching from a particular remote, add two new configuration variables "fetch.prune" and "remote..prune":

    • "fetch.prune" allows to enable prune for all fetch operations.
    • "remote..prune" allows to change the behaviour per remote.

    The latter will naturally override the former, and the --[no-]prune option from the command line will override the configured default.

    Since --prune is a potentially destructive operation (Git doesn't keep reflogs for deleted references yet), we don't want to prune without users consent, so this configuration will not be on by default.

提交回复
热议问题