-
-
Save sumardi/5559896 to your computer and use it in GitHub Desktop.
# New repository | |
mkdir <repo> && cd <repo> | |
git init | |
git remote add –f <name> <url> | |
git config core.sparsecheckout true | |
echo some/dir/ >> .git/info/sparse-checkout | |
echo another/sub/tree >> .git/info/sparse-checkout | |
git pull <remote> <branch> | |
# Existing repository | |
git config core.sparsecheckout true | |
echo some/dir/ >> .git/info/sparse-checkout | |
echo another/sub/tree >> .git/info/sparse-checkout | |
git read-tree -mu HEAD | |
# If you later decide to change which directories you would like checked out, | |
# simply edit the sparse-checkout file and run git read-tree again as above. | |
# http://schacon.github.io/git/git-read-tree.html#_sparse_checkout |
the .git folder is still very large after performing the Existing repository script. How to fix?
@zhaox27-medtronic, a sparse checkout doesn't affect how much commit history is cloned into the .git
folder, only how much is checked out into the current worktree.
To limit the size of .git
folder you can change the depth that you clone/fetch (the depth is the number of commit history you download).
See git-fetch and look at the --depth
flag.
if I use like this command line
echo some/dir/ >> .git/info/sparse-checkout
there will be a folder which names some ,
how could I set command that not produce this folder
#This way will work. Please note the space between each path.
git init
git config core.sparsecheckout true
echo 'some/dir/' 'another/sub/tree/'| out-file -encoding ascii .git/info/sparse-checkout
to specify what should not be checked out you can use the following pattern:
reference: https://git-scm.com/docs/git-read-tree#_sparse_checkout