Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make git push fail when there are uncommitted changes

Tags:

git

git-push

I normally use something like the following to test my changes, and if they are ok, push them to the remote repository:

mvn install && git push

Works great except for that stupid user that has written beautiful code, but forgot to commit it /facepalm/

Is there a way to make git push fail when there are uncommitted changes? Or maybe a separate command that checks for uncommitted changes, so I get something like this:

mvn install && git --clean-only push

or

mvn install && git is-clean && git push
like image 804
Jens Schauder Avatar asked Aug 12 '14 13:08

Jens Schauder


People also ask

Can you git push with uncommitted changes?

Hence, your uncommitted changes won't be pushed to remote in any scenario unless you commit those and then do git push .

What happens if you commit and dont push?

So commiting changes without pushing allow the save-load behaviour done locally during development. Once you are happy with your work, you then commit AND push.

What happens if git push is interrupted?

The upstream Git repository will be oblivious to your attempted push, and no change will occur upstream. Unfortunately however, as it doesn't do anything with the half-pushed files, it doesn't store it and then expect a continuation of the push later on either.


1 Answers

You could probably use mvn install && git diff --quiet --cached && git push. This checks for uncommitted changes. If you'd like to check for unstaged changes, use git diff --quiet instead (or both).

like image 53
sschuberth Avatar answered Oct 13 '22 19:10

sschuberth