Using git source control with a website

核能气质少年 提交于 2021-02-19 03:33:45

问题


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:

  1. Establish Git repository on your local environment.
  2. Establish Git repository on Bitbucket with Master branch and push local->master
  3. Activate Deploybot Account, populate with FTP credentials to your Production site
  4. Set up automatic deployments from Deploybot to Production. This will check Bitbucket for newly merged commits and deploy them automatically
  5. 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

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