DEV Community

Discussion on: Oops, I just pushed a git commit to the wrong branch. What now?

Collapse
 
mgohin profile image
Maelig • Edited

Better use git push --force-with-lease to be sure you don't override your colleagues work if they pushed before you pushed force.

More info :

Collapse
 
sivaraam profile image
Kaartic Sivaraam

Yeah. Its good to use --force-with-lease instead of --force. Its also worth noting the case in which --force-with-lease might not work as you expect it to.

Quoting from –force considered harmful; understanding git’s –force-with-lease:

A more subtle problem is that it is possible to trick git into thinking that a branch has not been modified when it has. The main way that this would happen under normal usage is when Bob uses git fetch rather than git pull to update his local copy. The fetch will pull the objects and refs from the remote, but without a matching merge does not update the working tree. This will make it look as if the working copy of the remote is up to date with the remote without actually including the new work, and trick --force-with-lease into overwriting the remote branch, as you can see in this example: ...

Thread Thread
 
mgohin profile image
Maelig

that's evil ! :)