I have very poor knowledge about git and would like to ask for help.
I have a linux(-only) application which shall only be “downloaded” (i.e. cloned) with git. On startup, the app shall ask the git “master server” (github) for whether there are updates.
Does git offer a command to check for whether there is an update (without really updating – only checking)? Furthermore, can my app read the return value of that command?
If you do not want to merge, you can just
git fetch yourremote/yourbranch, the remote/branch specification usually beingorigin/master. You could then parse the output of the command to see if new commits are actually present. You can refer to the latest fetched commit as eitheryourremote/yourbranchor possibly by the symrefFETCH_HEAD.Note: I was reminded that
FETCH_HEADrefers to the last branch that was fetched. Hence in general you cannot rely ongit fetch yourremotewithFETCH_HEADsince the former fetches all tracked branches, thus the latter may not refer toyourbranch. Additionally,That being said, here are some options for checking for updates of a remote branch, which we will denote with
yourremote/yourbranch:0. Handling errors in the following operations:
0.1 If you attempt to
git fetch yourremote, andgitgives you an error likethat probably means you don’t have that remote-string defined. Check your defined remote-strings with
git remote --verbose, thengit remote add yourremote yourremoteURIas needed.0.2 If
gitgives you an error likethat probably means you don’t have
yourremote/yourbranchlocally. I’ll leave it to someone more knowledgeable to explain what it means to have something remote locally 🙂 but will say here only that you should be able to fix that error withafter which you should be able to repeat your desired command successfully. (Provided you have defined
git remote yourremotecorrectly: see previous item.)1. If you need detailed information,
git show yourremote/yourbranchand compare it to the currentgit show yourbranch2. If you only want to see the differences,
git diff yourbranch yourremote/yourbranch3. If you prefer to make comparisons on the hash only, compare
git rev-parse yourremote/yourbranchtogit rev-parse yourbranch4. If you want to use the log to backtrack what happened, you can do something like
git log --pretty=oneline yourremote/yourbranch...yourbranch(note use of three dots).