What is the command equivalent to git clone -b on old Git versions?
A friend is stuck with an old version of Git (I think he said 1.5?), where he says the
-b <branch> option is not supported. I can't wrap my head around it, so I really hope someone could help:
What would be the equivalent of the following command, without using
git clone -b $BRANCH $REPO
EDIT: I originally asked for
git checkout - that's not what I meant. Sorry!
in older git this required two steps:
git branch $BRANCH $FROM_COMMIT git checkout $BRANCH
notice i used
$REPO in your question looks odd and misleading – you can only create branches from commits, not from other repositories.
editing my answer, since the question was altered. reading the manpage for git clone, we can see that
Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out.
to achieve this effect with an older git version we would use:
git clone $REPO git branch $BRANCH origin/$BRANCH git checkout $BRANCH
this will set your local
HEAD to the newly created
$BRANCH which is pointing to
(hopefully i'm not mistaken – i don't have a git install here to test …)
He should be able to do:
git clone -n $REPO cd <reponame> git checkout -b $BRANCH origin/$BRANCH
I've checked that the options are valid for v1.2.0 so this should be good if he's on at least 1.5.
For reference, clone only gained the
--branch option in v1.6.5.
Read more... Read less...
That would be:
git clone -n $REPO git checkout -b $BRANCH origin/$BRANCH
If you don't fetch the default branch from the
you need to fetch the branch you actually want to track, and then create your own local branch.
I would have deleted this answer, but Charles Bailey's comments are interesting:
There's no point in fetching immeditately after a clone but you might want to pass
cloneto avoid the unnecessary checkout of the remote's default branch.
Also, you need the
I've just checked,
-bwas added to
If your friend is using a version older than this (which seems extremely unlikely) then you need to be more specific.