1

I have 2 remotes: origin and secondary, and I need to checkout 3 folders from the secondary remote in my local working directory. (Let's say common/one, common/two and common/three.)

I do it by using that:

git fetch secondary master
git checkout secondary/master -- common/one common/two common/three

It works for added and modified files, but not for removed ones. And I don't know what command I need to write to make it so.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Sebastien P.
  • 55
  • 1
  • 5
  • 1
    What do you expect to happen when checking out a removed file, that file to be removed from your working tree? That's not how checkout works. Checkout gets you the state of the (sub-)tree from the named commit. If you want to re-apply removal of files, you need to cherry-pick instead. – sschuberth Jul 03 '18 at 08:15
  • *"but not for removed ones"* -- `git checkout` copies a file from a specified commit into the index and then into the local tree. It doesn't care about the history of that commit, it doesn't know anything about the deleted files. You ask it to get all the files from the directory `common/one` as they are recorded in the commit `master` of the `secondary` remote and this is what it does. – axiac Jul 03 '18 at 08:24
  • Oh well, I didn't know `checkout` is working like this. Thanks for the information. But that doesn't help me with the main problem. – Sebastien P. Jul 03 '18 at 08:43
  • When fetching a specific branch from a specific remote, you can access it by using `FETCH_HEAD` so my `checkout` was bad. Then, in my use case, I've chosen to go with a simple "rm" – Sebastien P. Jul 03 '18 at 12:09

1 Answers1

0

As commented, and noted here, the proper sequence is:

git fetch <remote> <branch>
rm -Rf afolder
git checkout FETCH_HEAD -- afolder

See "What does FETCH_HEAD in Git mean?"

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250