2

I have Git setup to have access to two github repositories: the upstream remote that I don't have collaborator (write) access to, and the fork I created of that which I do have write access to. Below is what I get when I run git remote -v.

origin  https://github.com/samholmes1337/secret-society (fetch)
origin  https://github.com/samholmes1337/secret-society (push)
upstream    https://github.com/asm-products/secret-society.git (fetch)
upstream    https://github.com/asm-products/secret-society.git (push)

However when I try to run git fetch upstream in order to retrieve the latest changes and have them stored in a new branch called upstream/master, it pauses for a second and then nothing happens.

empty output of 'git remote -v'

And when I check my branches to see whether anything has been fetched, I just see the master branch and nothing else, as though there have been no changes retrieved. What is going wrong?

Sam Holmes
  • 1,594
  • 13
  • 31
  • Can you precise how you "check your branches"? – Gauthier Mar 30 '15 at 11:03
  • I run `git branch`, which just yields one result: `* master`. – Sam Holmes Mar 30 '15 at 11:08
  • would you please show the output of `cat .git/config` – Anas Al Hamdan Mar 30 '15 at 11:09
  • 2
    I see, you need `-a` to show the remote branches, as per both answers you got so far. – Gauthier Mar 30 '15 at 11:09
  • Oh hang on so `git fetch upstream` _doesn't_ place them in a local directory? Or it does and there's just nothing new in the remote repository? – Sam Holmes Mar 30 '15 at 11:11
  • Your local directory reflects what is *checked out*. With `fetch` you fetch the commits you want, but the new data is only in your `.git/`. Your local files won't change until you run `checkout` on these commits. This is what I mean in my answer, `git checkout FETCH_HEAD` updates your local files with what you just fetched. – Gauthier Mar 30 '15 at 11:28
  • And putting the newly fetched commits in a local branch makes them easier to access, and to integrate if you want to keep them. It really sounds like you want to `pull`. – Gauthier Mar 30 '15 at 11:30

3 Answers3

3

That should mean the remote tracking upstream branches are already up-to-date.

You can check that with:

git branch -avv

That will display all the branches, including the remote tracking one, with their associated SHA1.

As mentioned in the comments, even if the remote tracking branch are not up-to-date and were actually fetching new commits, that would not place anything in the working tree.

Only a merge of upstream/master would do so. Since git pull = git fetch + git merge, doing a git pull might be more convenient.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    What does the third `v` in `-avvv` do? – Gauthier Mar 30 '15 at 11:08
  • Just checked the remote repository and forced it out-of-sync, it now works correctly. Thank you! – Sam Holmes Mar 30 '15 at 11:18
  • @Gauthier same as the doubly verbose option, actually (http://stackoverflow.com/a/4952368/6309) – VonC Mar 30 '15 at 11:27
  • @VonC: I see no `vvv` in your link, only `vv`. Both do exactly the same thing on my machine (1.9.1), which is why I wondered about the *third* `v`. Another way to put it: what is the difference between `vv` and `vvv`. – Gauthier Mar 30 '15 at 11:33
  • @Gauthier my link was about the double verbose `-vv`. Any `v` you add after the first two are ignored. – VonC Mar 30 '15 at 11:45
2

git fetch only fetches the commits, it does no merging, no updating of your references (which are not remote references).

See with git branch -a if you have branches called remotes/upstream/*.

You can also get what you just fetched with git checkout FETCH_HEAD.

If you want your local master to reflect upstream's master, you need to git checkout master && git pull upstream master. This works if the history of master has not diverged (ie you have your local work in another branch). It fetches first, then merges the FETCH_HEAD to your local master, allowing you to see the new commits.

If you want to get a branch from upstream and create a local reference at the same time: git fetch upstream master:upstream_master.

Gauthier
  • 40,309
  • 11
  • 63
  • 97
1

git branch show local branches by default

you need to add -a- or --all to list both remote-tracking and local branches.

I suggest you look at git branch -h to check the other options.

Anas Al Hamdan
  • 768
  • 1
  • 5
  • 18