1

I have a repository with many brunches and I cloned it.

git clone myproject
cd myproject

Now I wish to switch to branch, other than master.

How should I do this?

git checkout -b mybranch

doesn't work, it creates new branch with given name instead.

5
  • 1
    git checkout mybranch
    – Ry-
    Apr 4 '18 at 22:08
  • This is one of the fundamental git commands. Surely you could have found the answer you needed by a quick search? Apr 4 '18 at 23:28
  • Git is supposed to make life easier .. But instead it forces us to learn the tool and makes life complicated. Why the hell on the earth I should checkout the whole repository rather than just checking out a specific branch..
    – Stunner
    Nov 4 '20 at 4:32
  • And GIT came up with multiple version of commands with same functionality to cover up the design mistakes and its naming conventions are too messy and ambiguous. Lot of people simply do "rm -rf" and checkout fresh copy if something is messed up in GIT.
    – Stunner
    Nov 4 '20 at 4:34
  • qph.fs.quoracdn.net/… This sums up the whole GIT
    – Stunner
    Nov 4 '20 at 4:35

Browse other questions tagged or ask your own question.