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 branch.
Is there a viable solution for forcing Git to use the prune mode when fetching / pulling without having to specify it every time?
When comparing Git pull vs fetch, Git fetch is a safer alternative because it pulls in all the commits from your remote but doesn't make any changes to your local files. On the other hand, Git pull is faster as you're performing multiple actions in one – a better bang for your buck.
prune " configuration variables and to behave as if the " --prune " command line option was given. Any git fetch or git pull will automatically prune.
git fetch --prune is the best utility for cleaning outdated branches. It will connect to a shared remote repository remote and fetch all remote branch refs. It will then delete remote refs that are no longer in use on the remote repository.
git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin .
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.<name>.prune
":
- "
fetch.prune
" allows to enable prune for all fetch operations.- "
remote.<name>.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With