Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push to live server

We have a website that has all its PHP/HTML/JS/CSS/etc files stored in a Git repository.

We currently have 3 types of computers (or use cases) for the repository.

  • Local developer: pull latest changes, make changes, commit to local repo, push to master server
  • Master server: central repository, all changes get pushed to the master server
  • Web server: changes are pulled down from the master server when deploying the website

So currently we:

local: git push origin master local: password: ******** local: ssh [email protected] webserver: password: ******** webserver: cd ~/domain.com/ webserver: git pull origin master 

So my question is: is there a way that from my local computer I can push straight to the web server?

ie.

local: git push origin master local: password: ******** local: git push webserver master local: password: ******** 
like image 813
Petah Avatar asked Sep 16 '10 15:09

Petah


1 Answers

Yes you can push directly to your webserver, but I wouldn't recommend it since you should only push to repositories cloned with the --bare argument. I'd utilize the git hook system to let the main repository automatically update the repo on the web server. Check out the post-update hook in:

http://git-scm.com/docs/githooks

This script could in turn login to the web server via ssh and do

cd ~/domain.com/ git checkout master git pull origin master 

This way you only need to focus on pushing to the central server and don't have to care about the web server, it will always be updated once a push has been made. If you can automate something, then automate it :)

I even found a nice article for you about logging in via ssh in a script (if you must use password, this is trivial if a ssh-key has been setup):

http://bash.cyberciti.biz/security/expect-ssh-login-script/

Hope this helps!

like image 172
ralphtheninja Avatar answered Oct 04 '22 06:10

ralphtheninja