Git push to live server

Viewed 65248

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 admin@webserver.example
webserver: password: ********
webserver: cd ~/domain.example/
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: ********
6 Answers
  1. Add remote $ git remote add server ssh://server_hostname:/path/to/git/repo
  2. Checkout temp branch on server $ git checkout -b temp
  3. Push changes $ git push server
  4. Checkout previous branch and delete the temporary one $ git checkout - # shorthand for previous branch, git checkout @{-1} $ git branch -d temp

I have more background information here: https://medium.com/@2upmedia/git-push-to-live-server-5100406a26

Related