Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

How do I clone all remote branches?

My master and development branches are tracked remotely on GitHub. How do I clone both these branches?

Answer

Cancel
7
  • 2
    So, if the name of the branch you checkout is the identical to the name of the remote branch, everything after the "/", then git will create a branch of the same name, everything after the "/", "tracking" that remote? And by tracking, we mean: git push, git pull, etc. will be done on that remote? If this is correct, then expand on your answer with more information, because I aggree with @Daniel, this answer deserves more rep. Jun 14, 2012 at 22:08
  • 5
    @BullfrogBlues, the answer to all your questions appears to be yes (I'm using git v1.7.7.4). I agree this behavior should be better known. (It's not in the manual for this version of git.) I actually don't like this behavior, I'd rather get an error and have to say git checkout --track origin/somebranch explicitly.
    – dubiousjim
    Jul 3, 2012 at 13:05
  • 4
    @dubiousjim: Actually, this is in the manual. git-checkout(1) says: "If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to 'git checkout -b <branch> --track <remote>/<branch>' " (Git V.1.8.1.1).
    – sleske
    Feb 27, 2013 at 9:01
  • 1
    What we need is $ git pull * <remote>/* - where "*" is a wildcard, so it pulls all branches, including those not yet on the local system. How to do this? Are we really supposed to checkout/pull every branch just to get the code pulled to our local system?
    – JosephK
    Feb 19, 2017 at 5:27
  • 1
    This does not answer the question at all. Jan 16, 2022 at 21:56