Syncing website files between local and live servers using GIT?

放肆的年华 提交于 2019-12-08 02:38:08

问题


Say I have two web servers, one local development and one live.

Under SVN I would checkout the website files to my local webserver's public_html directory and also to the live webserver's public_html directory. I would then work on the files directly on the local server and commit any changes to the central repository.

When I'm ready for those changes to go live on the live server, I would SSH in and perform an SVN update.

Essentially I have two working copies, one on live and one locally, though other users may also have working copies on their local machines. But there will only ever be one working copy on the live server. The reason for this is so that we can just perform SVN update on live server every time we want changes to be published.

How can a simiar workflow be accomplished using GIT?


回答1:


To model your current work flow almost exactly do:

  • Set up a git repo.
  • Clone the repo on the server and locally.
  • Work locally
  • git push to the git repo
  • ssh to server
  • git pull.

Another way to do it would be to set up a "production" branch in git, have a cron job that continually pulls this branch on the server, and then just merge and push to the "production" branch any time you want to publish your changes. Sounds like you need a more concrete branching strategy.

See: Git flow branching model && git flow cli tool

Good luck! This is a very solvable problem with git.




回答2:


You might find this useful: http://joemaller.com/990/a-web-focused-git-workflow/




回答3:


In your local working copy:

git push ssh://you@yourserver/path/to/your/wc

will push the commited changes in your local version to yourserver.




回答4:


Having a setup that triggers automatically pulling like leonbloy and codemac suggested may seem like a good idea at first but it tends to be very fragile. I suggest a different alternative.

http://toroid.org/ams/git-website-howto



来源:https://stackoverflow.com/questions/5186756/syncing-website-files-between-local-and-live-servers-using-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!