git shallow clone (clone –depth) misses remote branches

After doing a shallow clone,
to be able to checkout other branches from remote,

  1. Run (thanks @jthill):

    git remote set-branches origin '*'
    
  2. After that, do a git fetch -v

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


Step 1 can also be done manually by editing .git/config.

For instance, change the folloing line from:

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

to (replace master with *):

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

Leave a Comment