Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `git push -f` force push ALL of the tracking branches?

Tags:

git

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?

like image 702
gylaz Avatar asked Dec 11 '22 21:12

gylaz


1 Answers

Since it's January, 2016 now, I guess it's worth to add some updated info to this question:

  1. As hobbs said, git push --force behaves exactly like normal git push in terms of pushing current or all the changed branches.
  2. git push pushes either all branches or a single one dependent on this configuration of the push.default
  3. More details in this post , but in order to push current branch only, your .gitconfig should looks like:

    [user]
            name = User Name
            email = [email protected]
    [push]
            default = simple

  1. In order to see your .gitconfig in Unix-like OS just do cat ~/.gitconfig. This post shows to how to do this on Windows.
  2. Pushing current branch only (simple mode) become default only in Git 2.0 (released on 2014-12-17).
  3. Those, who is using Git 1.7 (or who has updated from 1.7), has matching mode as default mode (pushing all the branches).
like image 133
Alex Avatar answered Mar 02 '23 15:03

Alex