Why does `git push -f` force push ALL of the tracking branches?
git
Solution
Since it's January, 2016 now, I guess it's worth to add some updated info to this question:
- As hobbs said, `git push --force` behaves exactly like normal `git push` in terms of pushing current or all the changed branches.
- `git push` pushes either all branches or a single one dependent on this configuration of the `push.default`
- More details in this post , but in order to push current branch only, your `.gitconfig` should looks like:
[user]
name = User Name
email = example.mail@gmail.com
[push]
default = simple
- In order to see your `.gitconfig` in `Unix-like OS` just do `cat ~/.gitconfig`. This post shows to how to do this on Windows.
- Pushing current branch only (`simple` mode) become default only in Git `2.0` (released on `2014-12-17`).
- Those, who is using Git `1.7` (or who has updated from `1.7`), has `matching` mode as default mode (pushing all the branches).
Problem
Git version: 1.7.12.3 As the question states, that seems like a really bad idea to me. Without any additional flags or confirmations `git push -f` will force push all of the tracking branches to remote. If a developer has a few outdated branches, that are tracking remotes, and he executes that command, all of the tracking branches will have been rolled back to his outdated copies, which causes loss of valuable work. This can be done accidentally, or by someone not very experienced with git. It really seems like git should do a little more hand-holding in such a dangerous case, and require an additional flag, or ask for a confirmation. Is there a remedy for this?