1

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?

PforPython
  • 58
  • 7

1 Answers1

0

First, use git switch, not the obsolete git checkout command.

git switch is 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 git error message, since git switch will not be looking for files, but branches to switch to.

Second, if you do see origin/feature in git branch -a output, the guess mode of git switch will automatically create the local branch linked to the remote tracking branch origin/feature, equivalent to:

git switch -c orign --track origin/feature
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250