git config --global fetch.prune true
在所有 Git 存储库中始终为 git fetch 和 git pull 提供 --prune:
git config --global fetch.prune true
上述命令会在您的全局 Git 配置(通常为 ~/.gitconfig)中附加以下行。使用git config -e --global 查看您的全局配置。
[fetch]
prune = true
git config remote.origin.prune true
始终--prune,但来自一个存储库:
git config remote.origin.prune true
#^^^^^^
#replace with your repo name
上面的这个命令会在你的本地 Git 配置(通常是 .git/config)中添加最后一行。使用git config -e查看您的本地配置。
[remote "origin"]
url = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
fetch = +refs/heads/*:refs/remotes/origin/*
prune = true
您也可以在第二个命令中使用--global,或者在第一个命令中使用--local。
git config --global gui.pruneDuringFetch true
如果您使用git gui,您可能还会对以下内容感兴趣:
git config --global gui.pruneDuringFetch true
附加:
[gui]
pruneDuringFetch = true
参考文献
来自git help config的相应文档:
--global
对于写入选项:写入全局~/.gitconfig 文件而不是存储库.git/config,如果此文件存在而~/.gitconfig 文件不存在,则写入$XDG_CONFIG_HOME/git/config 文件。
--local
对于写入选项:写入存储库.git/config 文件。这是默认行为。
fetch.prune
如果为 true,则 fetch 将自动表现得就像在命令行上给出了 --prune 选项一样。另见remote.<name>.prune。
gui.pruneDuringFetch
如果git-gui 应该在执行提取时修剪远程跟踪分支,则为“true”。默认值为“false”。
remote.<name>.prune
当设置为 true 时,默认情况下从此远程获取也将删除远程上不再存在的任何远程跟踪引用(就像在命令行上给出了 --prune 选项一样)。覆盖fetch.prune 设置(如果有)。