My Requirement was to checkout a specific directory from a repo and also checkout each branch which has that directory and copy each branch directory to a target path.
For Example football is a repo and src/ronaldo is the directory which I am trying to checkout and football repo has Branch A,B,C,D. But src/ronaldo is only in branch A and B. Now I wanna checkout the directory from Branch A and B and copy it to target folder Messi.
I tried to do a sparse checkout a specific directory in a repo and I am able to do it using the below commands.
git clone --filter=blob:none --no-checkout --depth 1 --sparse <project-url>
cd <project>
Specify the folders you want to clone
git sparse-checkout add <folder1> <folder2>
git checkout
But I am not able to find the rest of the branch which has the directory. What other git commands need to be added here.
You could use
git rev-parse ${commit-ish}:${path}to test if thecommit-ishtracks a path. If it succeeds, it returns the sha1 value of the tree object. If it does not, it returns literally${commit-ish}:${path}and the exit code is not 0.There is another method to implement your requirement, without checkout and copy.
After clone, read the tree (if it exists) into a temporary index file.
Then checkout the index into the target folder.
Note that the ending
/cannot be omitted.