Advertisement
Advertisement


Why can I clone the main repository but not a branch?


Question

I have a branch of a repository on github I am trying to clone. i can clone the main repository at the url https://github.com/pmyusername/myrepository (not actual link since the data is private). However, I cannot clone the branch located at https://github.com/myusername/myrepository/tree/branchname . To clone the repository, I simply needed to run:

git clone https://github.com/myusername/myrepository

but if i try to run:

https://github.com/myusername/myrepository/tree/branchname

I receive the error:

fatal: repository 'https://github.com/myusername/myrepository/tree/branchname' not found

but I know it exists because i am copying and pasting it from the url. The problem might have to do with the fact that I pay to keep it private, but i don't think so. Does anyone have any ideas?

2013/10/31
1
0
10/31/2013 6:55:14 PM

Accepted Answer

I'll try to aggregate all the comments into a succinct response...
Step 1: git clone https://github.com/myusername/myrepository
Step 2: git fetch
Step 3: git checkout -b desired_branch # add origin/desired_branch to end of command line to set up remote tracking

UPDATE:
Just did a quick experiment with daniellarsson's suggestion, and it appears to work:
i:work> git clone -b metro [email protected]:user/project.git
i:work> cd project
I:\work\project> git branch -a
* metro
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/metro

2013/10/31
2
10/31/2013 6:51:04 PM

If you use a UI like GitEx, you can mention the branch you want to clone in the dialog box the appears. This would clone the repo with the branch checked out automatically.

enter image description here

2013/10/31