Skip to main content

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.

5
  • 1
    In other words you don't have to write -t? Commented Apr 7, 2014 at 16:47
  • 4
    I think there's an error in this answer. I originally did the command without -t and got You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. because there wasn't a local branch of the same name. I had to re-run with -t to fix. Commented Sep 23, 2015 at 16:38
  • 1
    This worked well for me - my colleague had added a new remote branch that I wanted to add to my local repo. I kept fetching but didn't see the new branch appearing locally. Didn't realize that I could just run checkout for it to create it. Thanks! Commented Jul 22, 2016 at 16:23
  • 2
    depends on git versions. Latest version, as said elsewhere here, only needs git checkout <name of branch on origin>. BE CAREFUL WITH SAME-NAME LOCAL vs REMOTE BRANCHES - they will mess stuff up Commented Jul 14, 2017 at 11:20
  • --all is never a good idea, because it will download every file on every branch. It will take more time and space. It's better to be specific with the branch name and do like this Commented Apr 13, 2020 at 19:51