Skip to content

Instantly share code, notes, and snippets.

@LukeTully
Created December 10, 2016 02:56
Show Gist options
  • Save LukeTully/bed4620e9faacc31956cc23e98336235 to your computer and use it in GitHub Desktop.
Save LukeTully/bed4620e9faacc31956cc23e98336235 to your computer and use it in GitHub Desktop.
Simplified instructions on how to host a git repo

How to setup and work with a remote git repo on your own server

Sites like Github and Bitbucket make it ridiculously easy to setup public and private remote repos, which might make a lot of sense for your team. Sometimes there is an added cost to this though, whether financially or simply introducing another third-party dependency into your project.

Setting up your own git repo is easy and allows you to host your versioning system on your own server.

Getting started on the remote server

We'll need to set up a dedicated user to manage the repos.

  1. su - // Enter super user
  2. adduser git // Create the new user with home directory
  3. su git // Login as that user
  4. cd ~/ && mkdir .ssh
  5. cd .ssh
  6. touch authorized_keys

On the client

Optional: Installing ssh-copy-id

ssh-copy-id is a handy package that allows you to copy your local machine's public key to the authorized_keys file on the remote machine.

I use the homebrew package manager on macOS which, if you don't, you can find more information on at http://brew.sh/

brew install ssh-copy-id

  1. ssh-keygen -C "your@email.com" // Generate a new rsa key
  2. ssh-copy-id <user@server> // Copies rsa keys to the authorized_keys file on the host
  3. mkdir gitDirectory // Create folder for wherever you'll want the git repo
  4. cd gitDirectory && git clone user@server:<repo.git>
  5. git pull origin <branch> // or do an initial commit and push it up to the server

Other notes: To push a branch up to the server:

  1. git checkout -b feature_branch_name
  2. ... edit files, add and commit ...
  3. git push -u origin feature_branch_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment