问题
My partner and I have been dabbling with the idea of pushing and pulling from a repo that affects files viewable by the general public as opposed to storing the repos in a hidden location and just FTPing files when we feel they're good to go. While being able to directly push to the "live site" would be extremely convenient, I'm wondering what negative repercussions (if any) this would incur.
Thanks a lot!
回答1:
I would recommend pulling rather than pushing if going this route.
Always pull the finished product and do not do merges on the live server, for if there are conflicts you will be scrambling to fix them. Do all your merging, etc on your testing environment. Once all is good there, push the finished results to your 'bare' repo for the production branch and then from the production machine git pull
from it.
Yes it could be another point of failure however I think the benefits outway the cons.
回答2:
A VCS isn't supposed to be a deployment tool (see Using git below web root in production.): a simple ftp of one file (created with git archive
) would be enough.
If you want to use Git, use a bare repo on the server side to push to, and a post-receive
hook to update a working tree which would represent your site.
回答3:
It sounds like you are a candidate for scripted deployments. I would highly suggest looking into Capistrano and Webistrano. With these tools, you can deploy from a publicly available git repo easily and update only the code necessary on the server. A cached copy of the repo is held on the server, so you are only transmitting the change sets. The two tools I mentioned also allow you to easily roll back changes, manage database migrations, etc. Webistrano is essentially a web front-end to Capistrano, which is a ruby gem. I've also heard good things about Vlad, but I'm not as familiar with it. Best of luck.
回答4:
I "Push" my local development to the Live Server this way:
1.- Configure a hook on the server
.git/hooks/post-receive
including this lines:
git pull
git reset --hard
Warning: reset --hard will remove any changes on the live workspace. (See below)
2.- Give Executable rights to the file
chmod +x .git/hooks/post-receive
3.- Allow the "non-bare" repository on the live server to receive the Push
git config receive.denyCurrentBranch ignore
I work on my local copy (for development), which was cloned directly from the live server. and deploy by just
git push
In order to avoid conflicts I have the convention of: Always Pull before pushing Never work on the live site or commit on the server.
I hope you find this method useful.
来源:https://stackoverflow.com/questions/5490434/git-live-server-best-practices