How to clone a snapshot of a remote repository at a specific branch?

Posted on In QA

I know that one can make a zip of the current branch by:

git archive -o archive.zip HEAD

However, at situations, one may want to clone a copy/snapshot of remote repository at a specific branch because:

1) The repository is large with long history and cloning the whole history takes too much time.

2) What I want is a specific branch’s “snapshot” not the master branch’s.

To take a snapshot (no history, only files at HEAD) from branch br1 from git@git.example.com:repo:

git clone -b br1 git@git.example.com:repo --depth 1

-b br1 makes git clone the branch br1.

--depth 1 makes git only fetch the history of depth 1

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *