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?
On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch.
git push uploads all local branch commits to the corresponding remote branch.
A very easy way to do it would be to simply call
git push -n
(the "-n" is short for "--dry-run", which means that instead of doing the push, it will instead tell you what it would have pushed)
If it says "Everything up-to-date", then you've already pushed everything to origin.
Alternately, it will give you a list of all the commits that have not yet been pushed to origin.
Or if there are changes on origin that you haven't yet pulled down, then it might complain about potential merges which would be caused by pushing (this duplicates the "has some changes" checking you're already doing)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With