tags:

views:

747

answers:

1

Git clone will behave copying remote current working branch into local. Is there any way to clone a specific branch by myself without switching branches on remote repo? Thanks

+2  A: 
git init
git remote add add -t refspec remotename host:/dir.git
git fetch

But IIRC, by default clone fetches all branches from remote, not current working branch.

Michael Krelin - hacker
Thanks. I figured out using below method.git clone <remote_repo>git checkout -b <wanted_branch> origin/<wanted_branch>git branch -D master
Scud
That's awesome -- I didn't realize you could specify just a single refspec like that. But did you mean "git remote add origin -t refspec etc..."?
ebneter
I think so, and you will get [remote "origin"] fetch = +refs/heads/(refspec):refs/remotes/origin/(refspec) instead of fetch = +refs/heads/*:refs/remotes/origin/*
Scud
ebneter, yes, I forgot the "remote" section name.
Michael Krelin - hacker
Scud, honestly, I prefer `vim .git/config` for these needs. This way I sure know what am I to get ;-)
Michael Krelin - hacker