I’ve recently had to do a
git push -f which not only pushed the branch I’m on, but also all my other local branches, overriding the remote ones.
Fortunately for my teammates and I, the other branches were not crucial.
This behavior is due to Git’s push.default option set to matching, which means Push all matching branches. That’s nonsense to me considering the problems it may cause.
This can be changed of course, by setting the push.default to another value:
- nothing: do not push anything.
- matching: push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
- tracking: push the current branch to its upstream branch.
- current: push the current branch to a branch of the same name.
The most suitable option in most of situations, in my opinion, is the tracking option.
Happy versionning and be careful!