1

Suppose I do git fetch origin and I get the following output:

From origin
 * [new branch]      develop    -> origin/develop
 * [new branch]      new        -> origin/new

What does this syntax mean ? And sometimes it outputs different stuff, if I do git fetch origin develop I get the following output:

From origin
 * branch            develop    -> FETCH_HEAD
   f3beeb4..2b38122  develop    -> origin/develop

So here the syntax is different. Why? I'd appreciate a short description of each of these syntax's.

EDIT:

Sorry guys for not being more clear about my question. I'm actually interested in syntax/logic for these pieces:

 * [new branch]      develop    -> origin/develop
 * [new branch]      new        -> origin/new

 * branch            develop    -> FETCH_HEAD
   f3beeb4..2b38122  develop    -> origin/develop

And not for this one git fetch origin.

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488

4 Answers4

2

git fetch will connect to a remote repository. It will (per default) create "remote branches" inside the local repository, which are nothing but ordinary refs named like remotename/branchname.

If a new branch is detected on the remote repository, git fetch will create a new "remote branch":

 * [new branch]      new        -> origin/new

On the remote side (of the remote called origin) there was a new branch called "new". git therefore creates "origin/new" in this repository.

If the local "remote branch" is different from the branch on the remote repository, git will update it:

   f3beeb4..2b38122  develop    -> origin/develop

Here "origin/develop" was pointing to commit f3beeb4 but someone pushed to the remote repostitory and it therefore now points to 2b38122. Therefore git will update the "remote branch" from f3beeb4 to 2b38122.

If you specify an explicit branch name, git will store it in a special ref called "FETCH_HEAD". This will print like this:

 * branch            develop    -> FETCH_HEAD
michas
  • 25,361
  • 15
  • 76
  • 121
  • thanks, can you please elaborate on why sometimes git shows this branch update `f3beeb4..2b38122 develop -> origin/develop` and sometimes `* branch develop -> FETCH_HEAD` fetch_head update? What does the `* branch` mean in the latter syntax? – Max Koretskyi Jan 31 '15 at 08:57
  • You should get the first message whenever there are new commits in the remote repository. (In this case `git` needs to update the local ref.) You should get the second message whenever you specify an explicit branch like in `git fetch origin develop`. (In this this explicity specified branch will be stored in FETCH_HEAD.) The first column of the output shows what kind of ref (branch/tag/etc) it talks about. the second column is the remote ref name and the third column is the local ref name. – michas Jan 31 '15 at 09:02
1

git fetch updates the remote tracking branches (in this case new and develop).

git fetch origin develop stores fetched value of develop branch in .git/FETCH_HEAD.


Update:

Found a stackoverflow post with good description for the same (here).

Community
  • 1
  • 1
nitishagar
  • 9,038
  • 3
  • 28
  • 40
1

The documentation for git-fetch makes it somewhat clear.

  • git fetch origin is really git fetch <repository>. You're telling Git where to fetch updates from, and it doesn't necessarily have to be a previously added remote - it could be a URL if you wanted.

    In your project, you can have as many remotes as you require; normally, though, only one remote is needed, and by convention it's origin.

    From the docs, if that's omitted, origin is the default unless you've got an upstream branch configured:

    When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch.

    If you've only got one remote, then this is mostly pointless to do; if you want to specifically fetch from a different remote, this is when you'd actually use this form.

  • git fetch origin develop adds the <refspec> argument to the above command. It's basically telling Git which ref to fetch, and which local ref to update. It will store the result of this fetch inside of a short-lived ref called FETCH_HEAD, not the branch directly.

Community
  • 1
  • 1
Makoto
  • 104,088
  • 27
  • 192
  • 230
1

git fetch origin basically updates your remote-tracking branches, which means that all remote repository branches are copied to your local repository. The general command would be git fetch <remote>, where remote in this case is origin. The output then displays the branches that were downloaded:

  • develop, which is a and pointing to (remote) origin/develop (hence the ->) and is a new branch
  • new which points to (again remote) origin/new and is also a new branch

git fetch origin develop or in general git fetch <remote> <branch> does the same as above, but only fetches the specified <branch>, which is develop in your case.

References:

solimant
  • 809
  • 9
  • 15