git shallow clone (clone –depth) misses remote branches

After cloning a remote repository it does not show any remote branch by -a option. What could be the problem? How to debug it? In this snippet two of the remote branches are not shown:

$ git clone --depth 1 git://
$ cd pythonwebkit
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
$ git --version
git version

Tried the same command on another machine, it works well:

  • git working on two branches simultaneously
  • Display all first-level descendant branches using Git
  • git remote merge commit causing false dependencies in gerrit
  • GIT: commit changes to old/safe branch while in new/dirty/dev branch without checking out or losing unstaged data
  • git: How to create a branch of my current work, but stay on my original branch
  • Listing each branch and its last revision's date in git
  • $ git clone --depth 1 git://
    Receiving objects: 100% (186886/186886), 818.91 MiB | 3.44 MiB/s, done.
    $ cd pythonwebkit/
    $ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
    $ git --version
    git version 1.7.1

    Tried also cloning another repo, it works well. Though I can try it on this machine again, but it would be better to know what’s wrong.

    Any suggestions or hints will be more than welcome.

    Edit: Answer summary: Since git version the “–depth” and “–no-single-branch” need to be used together to get the same behavior as before. This is deemed a bug fix.

  • Cannot delete a remote branch created unintentionally
  • Is `git merge` able to display every change (w.r. to a common ancestor) as merge conflict?
  • Alter message in Gerrit code review
  • How to get a side-by-side view with difftool
  • Creating a Subversion branch
  • How do I make git understand that its “push” has failed? Git push failed. Cannot add files to a commit now.
  • 3 Solutions collect form web for “git shallow clone (clone –depth) misses remote branches”

    The behavior is correct, after the last revision the master-branch is (since this is the primary remote’s HEAD) the only remote-branch in the repository:

    florianb$ git branch -a
            * master
              remotes/origin/HEAD -> origin/master

    The full clone offers new (all) branches:

    florianb$ git branch -a
            * master
              remotes/origin/HEAD -> origin/master

    Shallow clones

    Due to the shallow-description in the technical documentation, a “git-clone --depth 20 repo […] result[s in] commit chains with a length of at most 20.” A shallow clone therefore should contain the requested depth of commits, from the tip of a branch.

    As – in addition – the documentation of git clone for the --single-branch-option describes:

    “Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. When creating a shallow clone with the --depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches.

    Therefore a shallow clone (with the depth-option) only fetches only one single branch (at your requested depth).

    Unfortunately both options (--depth and --single-branch) have been faulty in the past and the use of shallow clones implicits unresolved problems (as you can read in the link I posted above), which is caused by the given history-rewrite. This leads in overall to somewhat complicated behavior in special cases.

    After I’ve done the shallow clone,
    to be able to checkout other branches from remote,

    1. I edit the file from .git/config:

      fetch = +refs/heads/master:refs/remotes/origin/master

      and change it to

      fetch = +refs/heads/*:refs/remotes/origin/*
    2. After that, I do a git fetch -vvv

    3. Finally git checkout the-branch-i-ve-been-looking-for


    Also by using @jthill’s solution on the comment,

    git remote set-branches origin '*'

    will have same effect as step 1. After that, proceed to step 2 and 3.

    From reading the responses and the comment from @jthill, the thing that worked best for me was to use the set-branches option on the git remote command:

    $ git clone --depth 1
    $ git remote set-branches origin 'remote_branch_name'
    $ git fetch --depth 1 origin remote_branch_name
    $ git checkout remote_branch_name

    This changes the list of branches tracked by the named remote so that we can fetch and checkout just the required branch.

    Git Baby is a git and github fan, let's start git clone.