I have a two branches main and feature branch. In both the branches there are two folders f1 and f2. There is a file inside f1 folder called file1.txt.
main branch structure
-root
- f1
- file1.txt
- f2
feature branch structure
-root
- f1
- file1.txt
- f2
I want to clone f1 folder and its content using sparse checkout and after that I want to switch branches. How can i do that?
What I have tried:
git clone <link to repo> --depth 1 --filter=blob:none --sparse
cd <folder name>
git sparse-checkout set f1/
git fetch --all
git branch -a
git checkout feature
doing this i get this error "error: pathspec 'feature' did not match any file(s) known to git"
can someone guide me here?
First, use
git switch, not the obsoletegit checkoutcommand.git switchis made to not work with files, but only branches.So there won't be any
pathspec 'feature' did not match any file(s) known to giterror message, since git switch will not be looking for files, but branches to switch to.Second, if you do see
origin/featureingit branch -aoutput, the guess mode ofgit switchwill automatically create the local branch linked to the remote tracking branchorigin/feature, equivalent to: