22

I am asked to take clone of project repository from GitHub server.

There are three branches on server: master, qa and dev.

After taking clone to the project, how can I checkout qa or dev branch as both the branches are not on my local machine?

I tried the command

git checkout qa

it raised an error

$ git checkout qa error: pathspec 'qa' did not match any file(s) known to git.

Lali
  • 2,816
  • 4
  • 30
  • 47
  • I edited the question @Biffen – Lali Aug 27 '15 at 09:57
  • *Any* Git tutorial will tell you how to switch branch, probably in the first chapter. – Biffen Aug 27 '15 at 09:58
  • I know to switch a branch, --git checkout branchName, but this is when you have that branch on your local machine. – Lali Aug 27 '15 at 09:58
  • Did you try `git checkout qa`? – Biffen Aug 27 '15 at 10:02
  • Yes, it doesn't work – Lali Aug 27 '15 at 10:06
  • I don't know why it is downvoted? Is there some thing not clear? or question doesn't make sense anyway? – Lali Aug 27 '15 at 10:09
  • ‘*Doesn't work*’ will *not* help anyone solve your problem! *How* doesn't it work? What happens? – Biffen Aug 27 '15 at 10:09
  • As for the downvote: Could it be the lack of information in the question? Preferably, it should have included *from the start*; the command used to clone, how you determined that the branches were *not* in your local repository, the commands you've tried to switch branch and *the output* thereof. – Biffen Aug 27 '15 at 10:16
  • What is the basic knowledge about git commands, I ignored it to mention here, because anyone who knows a.b.c. of git, also knows how to 'clone'. And how I came to know that there are other branches on the server, I am not sitting in jungle, but in my office besides my colleagues. So I think it doesn't matter. – Lali Aug 27 '15 at 10:31
  • So everything's working, then? Great! If you have a question, you will have to supply some background. – Biffen Aug 27 '15 at 10:33
  • Check the answers, they got the things, but you could not. Thank you very much. – Lali Aug 27 '15 at 10:34
  • Since `git clone`, `cd`, `git checkout` *ordinarily* work just fine, you must have done something out of the ordinary. Hence my asking for more information. – Biffen Aug 27 '15 at 10:38

1 Answers1

26

Suppose your project is called SomeProject library and you need branches qa and dev besides default master. Here's what you do:

git clone https://github.com/someperson/someproject.git
cd someproject
git checkout -b qa origin/qa
git checkout -b dev origin/dev

Now your local branches qa and dev track corresponding remote branches, and you can check them out:

git checkout qa
git checkout dev
Sahil Raj Thapa
  • 2,353
  • 3
  • 12
  • 23
Dmitry VS
  • 605
  • 5
  • 14