How to allow git to check for updates on the core server?

I have very poor knowledge of git and would like to ask for help.

I have a linux application (only) that needs to be "downloaded" (ie cloned) using git. At startup, the application should ask git "main server" (github) if there are any updates.

Does git provide a command to check for updates (no updates - only checks)? Also, can my application read the return value of this command?

+4
source share
3 answers

If you don't want to merge, you can just git fetch yourremote/yourbranch , the remote / branch specification is usually origin/master . You can then analyze the output of the command to see if new commits are actually present. You can refer to the most yourremote/yourbranch commit to both yourremote/yourbranch and symref FETCH_HEAD .

Note: I was reminded that FETCH_HEAD refers to the last branch that was selected. Therefore, you cannot rely on git fetch yourremote on git fetch yourremote at FETCH_HEAD , as the former selects all monitored branches, so the latter may not refer to yourbranch . Besides,

  • you end up getting more than necessary.
  • also refer to Jefromi's answer for viewing, but not uploaded changes.
  • The following are not necessarily the most compact formats, just readable examples.

Here are some options for checking for remote branch updates, which we will denote with yourremote/yourbranch :

0. Error handling in the following operations:

0.1 If you try git fetch yourremote and git git fetch yourremote error like

 conq: repository does not exist. 

probably means you don't have this deleted row. Check your given remote lines with git remote --verbose , then git remote add yourremote yourremoteURI as needed.

0.2 If git gives you an error like

 fatal: ambiguous argument 'yourremote/yourbranch': unknown revision or path not in the working tree. 

which probably means you don't have yourremote/yourbranch locally. I will leave it to someone more knowledgeable to explain what it means to have something deleted locally :-), but they will only say here that you should eliminate this error with

 git fetch yourremote 

after which you can successfully execute the desired command. (If you correctly defined git remote yourremote : see the previous item.)

1. If you need detailed information, git show yourremote/yourbranch and compare it with the current git show yourbranch

2. If you want to see the differences, git diff yourbranch yourremote/yourbranch

3. If you prefer to compare only the hash, compare git rev-parse yourremote/yourbranch with git rev-parse yourbranch

4. If you want to use the log to return, then you can do something like git log --pretty=oneline yourremote/yourbranch...yourbranch (note the use of three points).

+3
source

If you really don't want to use bandwidth and fetch new commits, but just check if there is anything to fetch, you can use:

 git fetch --dry-run [remote] 

where [remote] is origin by default. You will need to parse the output, though, which looks something like this:

 From git://git.kernel.org/pub/scm/git/git 2e49dab..7f41b6b master -> origin/master 

so it’s much easier to just extract everything ( git fetch [remote] ) and then look at diff / log, for example. between master and [remote]/master .

+3
source

I would say git fetch is a potential solution. It only updates the index, not the working code. In the case of large sets of commits, this will require downloading compressed files / information, so it may be more than you want, but this is the most useful download you can do.

+1
source

All Articles