tags:

views:

142

answers:

3

Question

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 did commits to the remote repository. Now, I want to:

  1. Check whether there are any new commits from other people on the remote repository, i.e. "origin"?

  2. Say there were 3 new commits on the remote repository since mine last pull, I would like to diff the remote repository's commits, i.e. HEAD~3 with HEAD~2, HEAD~2 with HEAD~1 and HEAD~1 with HEAD.

  3. 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.

+9  A: 

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
Alan Haggai Alavi
+1 Thanks! Those were very helpful hints.
Lernkurve
A: 

A good way to have a synthetic view of what's going on "origin" is:

git remote show origin
jag
But that command doesn't show me how many commits there have been on "origin" since my last pull, does it? The way I understood it "git remote show origin" is a local operation and does not go over the network to fetch information.
Lernkurve
A: 

One potential solution

Thanks to Alan Haggai Alavi's solution I came up with the following potential workflow:

Step 1:

git fetch origin

Step 2:

git checkout -b localTempOfOriginMaster origin/master
git difftool HEAD~3 HEAD~2
git difftool HEAD~2 HEAD~1
git difftool HEAD~1 HEAD~0

Step 3:

git checkout master
git branch -D localTempOfOriginMaster
git merge origin/master
Lernkurve