1

I fetch a branch from a remote repository. How can I see that it has worked successfully? I expect that after this fetch I should have a (copy of) remote branch locally but I cannot find it (neither with git branch nor git branch -r nor git status). To me it looks like nothing has happened.

Roman
  • 124,451
  • 167
  • 349
  • 456
  • If there has been no output that implies to me that there is nothing to fetch. No new branches, no new commits, etc. – evolutionxbox Dec 06 '17 at 13:18
  • Possible duplicate of [Where to find changes due to \`git fetch\`](https://stackoverflow.com/questions/10678495/where-to-find-changes-due-to-git-fetch) – jos Dec 06 '17 at 13:27
  • There was some output as I have executed the fetch command: "* branch refs/changes/13/5857/2 -> FETCH_HEAD". But besides that, I do not know how to find what has changed. – Roman Dec 06 '17 at 13:27
  • Is this a follow-on from https://stackoverflow.com/questions/47674650/how-to-verify-that-a-remote-branch-do-exist? Did my thing about not configuring a remote turn out to be correct? (If so, it's the answer to this new question.) – Oliver Charlesworth Dec 06 '17 at 13:36

3 Answers3

2

First, to be sure to get an output, whether new branches or commits are actually found on the remote end, you can go for the verbose fetch :

git fetch -v

Then any non-updated remote branch will show up in the output as (for example)

= [up to date]       my_awesome_branch      -> origin/my_awesome_branch
= [up to date]       yet_another_branch     -> origin/yet_another_branch

But beyond this, even after having successful fetched and now having fresh references in your local repo, note that at this point only remote-tracking branches are updated to reflect the state of their counterparts on the remote end.

Your local branches, however, are still in the state they were before the fetch operation.

With this fetch output example :

$ git fetch
remote: Counting objects: 143, done.
remote: Compressing objects: 100% (143/143), done.
remote: Total 143 (delta 118), reused 0 (delta 0)
Receiving objects: 100% (143/143), 16.54 KiB | 1.65 MiB/s, done.
Resolving deltas: 100% (118/118), completed with 53 local objects.
From ssh://<repoNameRedacted>
 * [new branch]          feature-2541 -> origin/feature-2541
   433c28824..9924cc527  bugfix-9891 -> origin/bugfix-9891

If you were to now work on bugfix-9891 and get the most recent work, doing

git checkout bugfix-9891

...would point your HEAD at this local branch, allowing you to work on it, but you would not have the most recent commits, even though you fetched them just beforehand. They're in the remote-tracking origin/bugfix-9891 but still not in your local version bugfix-9891.

To actually incorporate these changes and work on top of them, you'll have to

git checkout bugfix/9891
git merge origin/bugfix/9891

Let's also note that there is a very common (though by no means necessary) way to automate the [fetch + merge with remote] process, namely :

git checkout bugfix/9891
git pull
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
1

After you fetched, to see what remote "master" has compared to your local "master", you ask Git to show you exactly this:

git log origin/master ^master

which means «all commits reachable from "origin/master" which do not include commits reachable from "master"» or, alternatively

git log master..origin/master

also, git diff master origin/master seems to address the question very simply I think.

Neha
  • 3,456
  • 3
  • 14
  • 26
0

I believe you meant to do GIT PULL, not GIT FETCH.

Or perhaps you meant to do GIT CLONE.

GIT FETCH will not change any files in your current branch, it will only update your repository.

Eliezer Berlin
  • 3,170
  • 1
  • 14
  • 27