git remote repository - quick setup

I like to keep my project backups offsite. This is one quick way to set up a repository on a server machine.

For this you need a remote server installed with Ubuntu 14.04 (or whatever).

First, login

1
ssh daniel@example.com

Update and install

1
2
sudo apt-get update
sudo apt-get install git

Create the git directory

1
2
cd /opt
sudo mkdir git

Create the project directory

1
2
sudo mkdir my-project.git
cd my-project.git

Initialize a bare repository

1
sudo git init --bare

Change ownership recursively

1
sudo chown -R daniel:daniel .

Logout. Back on your local machine, clone the bare repository

1
git clone daniel@example.com:/opt/git/my-project.git

Initialize a new project, whatever it may be. I use a lot of node, so I might do this:

1
2
cd my-project
npm init

Commit the changes

1
2
3
git add .
git commit -m "Hello, my-project"
git push origin master

At this point, you may be told to set your name and email

1
2
git config --global user.name "Daniel Bidulock"
git config --global user.email daniel@capitolhill.ca

Try pushing again

1
git push origin master

Bingo, bango, sugar in the gas tank!