问题
So I just want to set up Git on my server, but I'm running into a million problems so forget that.
Can I set up a normal git repo and then have my web server "auto" sync (just read, I guess) with the git repo?
I'm just part of a 2 person team and would prefer to use Git over any other version control.
回答1:
TL;DR
You can pull from your web server, but pushing to a non-bare repository requires a number of extra steps and can create problems. The right thing to do is usually to use a webhook or deployment tool that triggers on commits to a Git repository, but there are simpler options such as server-side cron jobs.
Use a Cron Job
On way to get the functionality you want is with a cron job. As a simplistic example, you could poll your git repository every minute and pull changes, e.g.:
* * * * * cd /path/to/www && git pull
If you have a web service that needs to be restarted to take advantage of modified resources, then you'd obviously need to do that too.
Use Hooks and Integrations
If you're using GitHub or other hosted repository service, you can often take advantage of integrations with providers like AWS or Heroku. In particular, Heroku is nice because each push to the master branch will recompile and redeploy your web service without requiring additional action.
For more information, see the following:
- GitHub integrations
- GitHub Webhooks API
- Heroku: Deploying with Git
Use a Full-Fledged Deployment Tool
If you have more complex requirements, you probably need a more capable deployment tool. One example is Capistrano, which is often used for Ruby on Rails projects but can also be used to manage deployments for other types of applications and frameworks. Some research will certainly turn up other deployment tools that you may like better, but it's a reasonable place to start.
回答2:
The easier solution to automatic deployments from a remote Git repo would most likely include using a deployment service.
Consider this setup:
- Bitbucket Free Edition with Master Repo (up to 5 users)
- Local Git Repo
- Deployment Service, such as http://deploybot.com/ (Free for 1 Repo)
Then, follow this general workflow:
- Establish Git repository on your local environment.
- Establish Git repository on Bitbucket with Master branch and push local->master
- Activate Deploybot Account, populate with FTP credentials to your Production site
- Set up automatic deployments from Deploybot to Production. This will check Bitbucket for newly merged commits and deploy them automatically
- Make your first commits locally, push and watch it go
Note: I hope you're not going to use automatic deployments for anything that can be considered critical, like your company website
来源:https://stackoverflow.com/questions/32815448/using-git-source-control-with-a-website