-1

From remote/ABC branch I want to pull everything except P folder (recursively) to the local current branch.

From remote/XYZ branch I want to pull only P folder (recursively) to the local current branch.

How to do this?

Dr.PB
  • 959
  • 1
  • 13
  • 34
  • 1
    "*From remote/ABC branch I want to pull everything except P folder…*" Pull everything and remove `P`. "*From remote/XYZ branch I want to pull only P folder…*" If your remote hosting supports `git archive` you can [use it](https://stackoverflow.com/a/18392680/7976758). Most commercial hostings disable `git archive`; you can try to resort to [`git clone --filter`](https://stackoverflow.com/a/52269934/7976758) (everything found in https://stackoverflow.com/search?q=%5Bgit%5D+fetch+one+directory). If nothing helps then alas there is no easy way to fetch just one directory. – phd Sep 23 '21 at 08:06

1 Answers1

1

I don't think you can do it easily because git need to know what branch you are on, it sounds like you want to use Git Submodules for this, each folder can be a different submodule, this will allow you to have different versions for the folders

However, if this is one time need, you can pull XYZ and copy P content aside, then pull ABC and copy and overridden P folder back from the copy you made, the result would be that you are on ABC branch but with changes for P folder that are the same as in XYZ. note that you will have local changes because you are on ABC but your P folder is different

Elisha
  • 4,811
  • 4
  • 30
  • 46