Clone from a branch other than master

user2510555 picture user2510555 · Jun 29, 2013 · Viewed 68.4k times · Source

I am trying to pull from a repository in Github. But I don't want to clone the master branch. I want to clone some other branch. When I try git clone <url>, I get the files from master branch. What should I do?

Also, suppose the code is updated in the repository and I want to get the latest code, should I again use git clone? Because the size of the project is huge. Also if I make changes to the project locally, and then I again use git clone, will the changes I made still be there? What if I don't want changes to be there?

I am not even sure if git clone is the right command. git pull or git fetch?

I am sorry, I am very new to git.

Answer

Aguardientico picture Aguardientico · Jun 29, 2013

Try this:

git init
git fetch url-to-repo branchname:refs/remotes/origin/branchname

EDIT

A better solution:

git clone -b mybranch --single-branch git://sub.domain.com/repo.git