Jaganathan Bantheswaran Jaganathan Bantheswaran - 3 months ago 23
Git Question

Git - could not checkout remote branch

Why is that

git pull
pulls everything including newly created remote branches but
git pull origin master
is not?

I'm using
git version 2.9.3.windows.2


When you specify no branches, the default settings are used. The default means to fetch and update all branches existing in the remote repository.

See documentation for details:

git pull [options] [<repository> [<refspec>…​]]

<refspec> specifies which refs to fetch and which local refs to update. When no <refspec>s appear on the command line, the refs to fetch are read from remote.<repository>.fetch variables instead (see git-fetch[1]).

Source: https://git-scm.com/docs/git-pull

The referenced documentation explains:

You often interact with the same remote repository by regularly and repeatedly fetching from it. In order to keep track of the progress of such a remote repository, git fetch allows you to configure remote.<repository>.fetch configuration variables.

Typically such a variable may look like this:

[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*

The example above will fetch all branches that exist in the origin (i.e. any ref that matches the left-hand side of the value, refs/heads/*) and update the corresponding remote-tracking branches in the refs/remotes/origin/* hierarchy.

Source: https://git-scm.com/docs/git-fetch#CRTB

The behavior is default because it allows you to synchronize the whole repositories at once. If you don’t want to update all local branches at once, use git fetch to synchronize the repositories and git merge origin/<branch> to update each single local branch.