There is a remote repo with directory structure:
-directory1
-file1_1
-file1_2
...
-directory2
-file2_1
-file2_2
...
I have a folder on a web hosting with a custom name, say, "/path/public_html".
How do I set up git on the web hosting, so my "public_html" tracks a subdirectory "directory2" of a remote repo?
So, in other words, I want to execute some form of git command on the web hosting and update public_html to the latest content of "directory2". I don't care about pushing back to repo from web hosting, if it helps.
I don't care about pushing back to repo from web hosting
In this case you could use the archive command. Something like this:
git archive --remote=remote_repo --format=tar branch_name path/to/directory2 > /path/public_html/dir2.tar && cd /path/public_html && tar xvf dir2.tar
You cannot clone directly directory2
content, only directory2
and its content, meaning you always have a directory2/
folder on your disk.
If you want to see directory2
content in public_html
(meaning not public_html/directory2/...
), then you need a symlink.
That being said, you can still clone and checkout only directory2
folder, instead of cloning the full repo, as described in "Is it possible to do a sparse checkout without checking out the whole repository first?"
That is:
git init /a/path
cd /a/path
git config core.sparseCheckout true
git remote add -f origin /url/remote/repo
echo "directory2/" > .git/info/sparse-checkout
git checkout [branchname] # ex: master
That would give a a/path/directory2
folder, than your public_html
can symlink
to.
If having a directory2
folder in public_html
does not bother you, then you could repeat the above commands in public_html
instead of a/path
.
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