user3240356
user3240356

Reputation: 95

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?"

Upvotes: 5

Views: 3054

Answers (2)

elquimista
elquimista

Reputation: 2271

As @edi9999 said above, --depth option fetches a single branch by default. If you want to fetch all other branches near the tip of the specified depth, you have to specify --no-single-branch option.

E.g.

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

Upvotes: 0

edi9999
edi9999

Reputation: 20554

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

Upvotes: 7

Related Questions