Home > Mobile >  Perform git sparse-checkout of everything except a list of subdirectories
Perform git sparse-checkout of everything except a list of subdirectories

Time:03-07

I have the following (mono)repo structure

└── dir1
    ├── subdir1
    │   ├── subdir1a
    │   ├── subdir1b
    │   └── subdir1c
    └── subdir2
        ├── subdir2a
        ├── subdir2b
        ├── subdir2c

└── dir2
└── dir3

I want to checkout everything except (say) subdir1b and subdir1c.

Is there a way to perform a sparse checkout of everything except perhaps some subdirs?

Asking because perhaps (if there is such a work around) it is easier to state to git what you do not want to be checkout rather than start listing everything that is to be checkout.

CodePudding user response:

Assuming you are using the Git 2.25 git sparse-checkout command, I just tested:

C:\Users\vonc\git>git clone --filter=blob:none --no-checkout https://github.com/git/git git2
Cloning into 'git2'...
remote: Enumerating objects: 200317, done.
remote: Total 200317 (delta 0), reused 0 (delta 0), pack-reused 200317
Receiving objects: 100% (200317/200317), 74.10 MiB | 26.40 MiB/s, done.
Resolving deltas: 100% (127965/127965), done.

C:\Users\vonc\git>cd git2

C:\Users\vonc\git\git2>git sparse-checkout init

C:\Users\vonc\git\git2>git read-tree -mu HEAD
remote: Enumerating objects: 459, done.
remote: Counting objects: 100% (392/392), done.
remote: Compressing objects: 100% (392/392), done.
remote: Total 459 (delta 0), reused 0 (delta 0), pack-reused 67
Receiving objects: 100% (459/459), 1.88 MiB | 9.14 MiB/s, done.

The result is a repository with no subfolders.

Lets start to add all subfolders, except Documentation\technical

# edit .git\info\sparse-checkout
/*
!/Documentation/technical/
# ... Add your other excluded folders

C:\Users\vonc\git\git2>git sparse-checkout reapply

The end result is the all git/git repository, without Documentation/technical/

  •  Tags:  
  • git
  • Related