How to check for changes on remote (origin) Git repository
What are the Git commands to do the following workflow?
Scenario
I cloned from a repository and did some commits of my own to my local repository. In the meantime, my colleagues made commits to the remote repository. Now, I want to:
-
Check whether there are any new commits from other people on the remote repository, i.e.
origin
? -
Say there were three new commits on the remote repository since my last pull, I would like to diff the remote repository's commits, i.e.
HEAD~3
withHEAD~2
,HEAD~2
withHEAD~1
andHEAD~1
withHEAD
. -
After knowing what changed remotely, I want to get the latest commits from the others.
My findings so far
For step 2: I know the caret notation HEAD^
, HEAD^^
etc. and the tilde notation HEAD~2
, HEAD~3
, etc.
For step 3: That is, I guess, just a git pull
.
You could git fetch origin
to update the remote branch in your repository to point to the latest version. For a diff against the remote:
git diff origin/master
Yes, you can use caret notation as well.
If you want to accept the remote changes:
git merge origin/master
git remote update && git status
Found this on the answer to Check if pull needed in Git
git remote update
to bring your remote refs up to date. Then you can do one of several things, such as:
git status -uno
will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.
git show-branch *master
will show you the commits in all of the branches whose names end in master (eg master and origin/master).If you use
-v
withgit remote update
you can see which branches got updated, so you don't really need any further commands.
A good way to have a synthetic view of what's going on "origin" is:
git remote show origin