简体   繁体   中英

Syncing website files between local and live servers using GIT?

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?

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.

您可能会发现这很有用: http : //joemaller.com/990/a-web-focused-git-workflow/

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.

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

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