Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git source control with a website

Tags:

git

web

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.

like image 440
slaw Avatar asked Jan 08 '23 11:01

slaw


2 Answers

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.

like image 196
Todd A. Jacobs Avatar answered Jan 18 '23 13:01

Todd A. Jacobs


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

like image 38
David Lerner Avatar answered Jan 18 '23 12:01

David Lerner