简体   繁体   中英

how to minimal clone repository to be able list branches and checkout single file

im looking for away to do clone as minimal as i can , so no source will be downloaded (checkout) then after i done the "minimal clone"
i need to be able to do :

git branch -r

to list all repo branches

Then select branch from the list and checkout only 1 file from the selected branch

i really want to avoid downloading and updating all repo source code. In this example i want to get all the remote branches of "develop"

what i tried to do "minimal clone" is:

git clone  --depth 1 --no-checkout https://user:pass@bitbucket.org/foo/project.git 

but then when i list the branches:

 git branch -r

im getting :

 origin/HEAD -> origin/develop
  origin/develop

and when i checkout origin/develop im getting all the sources

but it does download me all the repo sources .

im using git version 2.10.2.windows.1.

Initialize a repo instead of creating it by git clone ,

git init project
cd project
git remote add origin https://user:pass@bitbucket.org/foo/project.git

To list all the refs,

git ls-remote

If branches only,

git ls-remote --heads

Pick a branch, say develop , and fetch its last commit only,

git fetch origin develop --depth 1

Config sparse-checkout to checkout only 1 file, say path/to/foo.txt ,

git config core.sparsecheckout true
echo "path/to/foo.txt" >> .git/info/sparse-checkout

Checkout the only file,

git checkout develop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM