Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout to branch when git clone --depth 1 doesn't work

set -e
cd /source

git clone --depth 1 https://github.com/named-data/ndn-cxx.git

pushd ./ndn-cxx

git checkout -b release-build ndn-cxx-0.3.3

./waf configure

./waf

./waf install

popd

rm -rf ./ndn-cxx

I am running the above mentioned script, but getting the error: "Cloning into 'ndn-cxx'... /source/ndn-cxx /source fatal: Cannot update paths and switch to branch 'release-build' at the same time. Did you intend to checkout 'ndn-cxx' which can not be resolved as commit?"

like image 974
user3240356 Avatar asked Jul 13 '15 08:07

user3240356


Video Answer


1 Answers

By default, if you specify the --depth option, git will only fetch the master branch, so you won't be able to checkout to any other branch.

You can write the following :

git clone --depth 1 <url> --single-branch --branch <branch>

to retrieve the latest version of <branch> instead, like this:

git clone --depth 1 https://github.com/named-data/ndn-cxx.git --single-branch --branch ndn-cxx-0.3.3

You won't have to do a git checkout after the clone

like image 68
edi9999 Avatar answered Oct 14 '22 01:10

edi9999