git config --global fetch.prune true
To always --prune
for git fetch
and git pull
in all your Git repositories:
git config --global fetch.prune true
This above command appends in your global Git configuration (typically ~/.gitconfig
) the following lines. Use git config -e --global
to view your global configuration.
[fetch]
prune = true
git config remote.origin.prune true
To always --prune
but from one single repository:
git config remote.origin.prune true
#^^^^^^
#replace with your repo name
This above command adds in your local Git configuration (typically .git/config
) the below last line. Use git config -e
to view your local configuration.
[remote "origin"]
url = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
fetch = +refs/heads/*:refs/remotes/origin/*
prune = true
You can also use --global
within the second command or use instead --local
within the first command.
git config --global gui.pruneDuringFetch true
If you use git gui
you may also be interested by:
git config --global gui.pruneDuringFetch true
that appends:
[gui]
pruneDuringFetch = true
References
The corresponding documentations from git help config
:
--global
For writing options: write to global ~/.gitconfig
file rather than the repository .git/config
, write to $XDG_CONFIG_HOME/git/config
file if this file exists and the ~/.gitconfig
file doesn’t.
--local
For writing options: write to the repository .git/config
file. This is the default behavior.
fetch.prune
If true, fetch will automatically behave as if the --prune
option was given on the command line. See also remote.<name>.prune
.
gui.pruneDuringFetch
"true" if git-gui should prune remote-tracking branches when performing a fetch. The default value is "false".
remote.<name>.prune
When set to true, fetching from this remote by default will also remove any remote-tracking references that no longer exist on the remote (as if the --prune
option was given on the command line). Overrides fetch.prune
settings, if any.
git fetch
! See my answer below