1. Install Git
ssh myserver.com
sudo apt-get update
sudo apt-get install git-core
  1. Setup git user
sudo adduser git
sudo mkdir /home/git/.ssh
sudo cp ~/.ssh/authorized_keys /home/git/.ssh/
sudo chown -R git:git /home/git/.ssh
sudo chmod 700 !$
sudo chmod 600 /home/git/.ssh/*
  1. Using git user login to server with ssh,ssh [email protected]
  2. Create git repo on the server
mkdir myrepo.git
cd !$
git --bare init
  1. Push local code to server
git remote rm origin
git remote add origin [email protected]:myrepo.git
# or use below line to replay above two lines, if you already have a remote origin url
git remote set-url origin [email protected]:myrepo.git
git push origin master
git config branch.master.remote origin && git config branch.master.merge refs/heads/master
  1. Bonus points: Make SSH more secure

Edit the SSH config:

sudo vi /etc/ssh/sshd_config

And change the following values:

Port 2207
PermitRootLogin no
AllowUsers myuser git
PasswordAuthentication no

Where 2207 is a port of your choosing. Make sure to add this so your Git remote:

git remote add origin ssh://[email protected]:2207/~/myrepo.git