简体   繁体   中英

Git local repository for remote directory

I cannot find the answer to this anywhere. Is it possible to set up a local git repository for files on a webserver? I do not want to put the repo on the webserver because of a lack of space.

It sounds like you want a repo stored locally, but you want its work tree to coincide with a tree of content served by your web server.

There is not native support for this, but if you can map the underlying drive/directory that contains the content tree to a local path (ie treat it as a network shared drive) then you could make it work with git worktree

The details of setting the server up to share the content directory, and mapping that share locally, depend on OS (and maybe on your web daemon and how it's set up, though if it's just serving files from a local content directory then it shouldn't be an issue).

Note that when you add a worktree, git wants to see an empty directory to check out into. So you'll need a brief "outage window" during which the content tree can be empty. The procedure might then look like this

# First, map the content tree to ./web-content
# ...

# Now initialize a repo
mkdir repo-init
cd repo-init
git init

# Import the web content into the repo; must be in outage window
mv ../web-content/* .
git add .
git commit

# Re-make the repo as a "mirror" to remove the default work tree
cd ..
git clone --mirror repo-init repo
rm -rf repo-init
cd repo
git remote remove origin

# Now check the content back out to the server
git worktree add ../web-content master

# outage window can now end

You now have a local repo that is tracking the files on the web server. If you want to be able to pull (or push) to update the server, you'll have to configure appropriately (as you would if the repo were on the server).

Absolutely yes. The easiest way is to keep repository locally and just put code (only working directory) remotely using ftp/rsync. That's it. Your host do not need your repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM