I have some shell script where I want to check one of my git repos. I want to
know if that repos has everything committed and if it is pushed to master.
Before this test I make git fetch to make sure I have the latest changes.
I have found the way to check if the repo has some uncommitted changes:
if ! git --work-tree=$HOME/git/project --git-dir=$HOME/git/project/.git diff-index --quiet HEAD --; then
echo "Has some changes";
fi
But this is not the only thing I need. I also want to make sure that all my
local commits are pushed to master.
What is the easiest way to do so?
From Mark Longair’s great answer I understood that is is possible to check
that local git repo has everything commited and pushed but you need to run
several commands to do so.
I’ve written a small script that does all that and write in a frienly way what
has happened.
And you can also use exit code to find out if everything is commited and
pushed or not.
It is at Github: https://github.com/bessarabov/App-IsGitSynced and on CPAN: https://metacpan.org/module/App::IsGitSynced