0

how to Download single file/folder from a Private GitHub repository hosted on GitHub. The repository structure is like

AndroidApps/
├── FirstAnimation/ 
│   ├── app
│   └── build.gradle
|   └── gradle.properties
|   └── ...
|
└── NavigationHelp/
|   ├── app
|   └── build.gradle
|   └── gradle.properties
|   └── ...
|
└── ChatApp/
    ├── app
    └── build.gradle
    └── gradle.properties
    └── ...

And I want to download only the NavigationHelp folder and not clone the whole AndroidApps project.

note-(previously answer given on Stack overflow related to public folder which does not work for private repo)

1 Answers1

0
git clone -n --filter=tree:0 git@github.com:your/AndroidApps
cd AndroidApps                   # <--- forgot this line the first time, oops
git read-tree -um @:NavigationHelp

will get you just that folder and the barest sketch of the rest of the history. To make future pulls work,

git checkout -b sliced/NavigationHelp
git config branch.sliced/NavigationHelp.merge @{-1}@{u}
git config branch.sliced/NavigationHelp.mergeoptions -Xsubtree=NavigationHelp

and that'll let you pull updates but not merge back to the upstream branch. Read up on the commands and syntax I've used above and you'll learn to adapt this to check out anything else.

To merge back to the upstream branch, you'll either have to fetch it and do the merge yourself or convince GitHub to support subtree merges done on its servers, (if they don't already, I've never investigated).

jthill
  • 48,781
  • 4
  • 72
  • 120