Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created February 21, 2012 09:51
Show Gist options
  • Star 75 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save Integralist/1875544 to your computer and use it in GitHub Desktop.
Save Integralist/1875544 to your computer and use it in GitHub Desktop.
Basic set-up of remote git repository on a standard server

Set-up remote git repository on a standard server

The first thing to do is to install Git on the remote server.

Once you do that the rest of the process is split into three sections:

  1. Server set-up
  2. Local set-up (push commits)
  3. Server (pull commits)

Server set-up

  • ssh -pxxxx username@xxx.xxx.xxx.xxx (this is you connecting to your remote server)
  • cd ../ (this gets you to the 'absolute root' of the server)
  • cd www/..../ (navigate to the directory one level above your website directory - e.g. your website directory being where you would upload your HTML files etc)

Note: if (for example) your web directory is httpdocs then move up one level from there.

The following example assumes httpdocs is your web directory...

  • rm -rf httpdocs (remove the web directory - you'll recreate it again in a minute)
  • mkdir httpdocs && cd httpdocs (create new web directory folder and move inside it)
  • git init (initiate new git repo)
  • cd ../ (jump back up a directory level)

The following three commands are the black magic for getting a remote git repo setup:

  • git clone --bare httpdocs httpdocs.git
  • mv httpdocs httpdocs.backup
  • git clone httpdocs.git

Local set-up (push commits)

  • cd ~/Desktop/Sites/myWebsite
  • git init
  • git add *
  • git commit -m 'Start of new project'
  • git remote add origin ssh://username@xxx.xxx.xxx.xxx:xxxx/www/.../httpdocs.git
  • git push origin master

Server (pull commits)

  • cd ../
  • cd www/..../httpdocs/
  • git fetch
  • git diff origin/master
  • git merge origin/master
@muyaedward
Copy link

Very helpful

@johnchrishays
Copy link

Worked great! Would be helpful to have explanation for key commands (e.g. the black magic)

@adamkendall1
Copy link

Thank you so much! This is so simple to follow your instructions and get up and running with git repos.

This was super helpful. Thanks!

@simo97
Copy link

simo97 commented May 24, 2019

thanks for this man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment