Just to add on this, the reason why you cannot pull just a directory is because git uses data semantic tracking, not file semantic tracking, so you can seamlessly move code (or other data) in and out of files without having to tell the source tracking system (until you update of course.)
To clone git repository into a specific folder, you can use -C <path> parameter, e.g. Although it'll still create a whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax: cd /httpdocs git clone [email protected]:whatever .
Cloning only a subdirectory is not possible in Git. The network protocol doesn't support it, the storage format doesn't support it.
git fetch
git checkout HEAD path/to/your/dir/or/file
Where "path/...
" in (3) starts at the directory just below the repo root containing your ".../file
"
NOTE that instead of "HEAD", the hash code of a specific commit may be used, and then you will get the revision (file) or revisions (dir) specific to that commit.
In an empty directory:
git init
git remote add [REMOTE_NAME] [GIT_URL]
git fetch REMOTE_NAME
git checkout REMOTE_NAME/BRANCH -- path/to/directory
After much looking for an answer, not finding, giving up, trying again and so on, I finally found a solution to this in another SO thread:
How to git-pull all but one folder
To copy-paste what's there:
git init
git remote add -f origin <url>
git config core.sparsecheckout true
echo <dir1>/ >> .git/info/sparse-checkout
echo <dir2>/ >> .git/info/sparse-checkout
echo <dir3>/ >> .git/info/sparse-checkout
git pull origin master
To do what OP wants (work on only one dir), just add that one dir to .git/info/sparse-checkout
, when doing the steps above.
Many many thanks to @cforbish !
If you want to get the latest changes in a directory without entering it, you can do:
$ git -C <Path to directory> pull
Maybe this command can be helpful :
git archive --remote=MyRemoteGitRepo --format=tar BranchName_or_commit path/to/your/dir/or/file > files.tar
"Et voilà"
It's not possible. You need pull all repository or nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With