Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make `git push -f` "safe"

Tags:

git

Is there a way to use git push -f, but only origin/master hasn't changed since the last pull?

I only want to reorganize history, not overwrite file contents.

like image 933
Jay Bazuzi Avatar asked Mar 19 '23 04:03

Jay Bazuzi


1 Answers

There is an option called --force-with-lease for git push. Doing

git push --force-with-lease

will do exactly what you desire and only force-update the remote branch if it is still on the same version as your remote tracking branch (i.e. origin/branch).

You can also specify a revision explicitely if you want to check for another version:

git push --force-with-lease=branch:someCommitHash
like image 144
poke Avatar answered Mar 22 '23 08:03

poke