Skip to content

Instantly share code, notes, and snippets.

@andywenk
Created October 2, 2009 08:44
Show Gist options
  • Save andywenk/199567 to your computer and use it in GitHub Desktop.
Save andywenk/199567 to your computer and use it in GitHub Desktop.

Simple setup for starting with git

Andy Wenk - 02.10.2009

This is a note to myself how to create a git repository. I am assuming to have root access to an own server. In this case it's (again) a Debian Linux machine with running Lenny.

SSH keys


The clone, pull and push process uses ssh, so it is necessary to create keys. Use rsa instead of dsa because it's more secure. And don't forget to set a passphrase!

On the local machine

$ ssh-keygen -t rsa

Put the public key the machine you will place the git repositorys and add them to the authorized_keys

Install git


$ aptitude install git-core

Create a repository on the server


Here all the repos go in

$ mkdir /var/lib/git

A new repository

$ mkdir /var/lib/git/therepo

$ cd /var/lib/git/therepo/

$ git init

Initialized empty Git repository in /var/lib/git/therepo/.git/

Unless one file is in the repository, you cannot clone it

$ vi README

$ git add README

$ git commit README

Created initial commit fb17959: initialize

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README

Change the rights for the repo to an existing user

$ chown -R myuser:users /var/lib/git/therepo

configure git on the local machine


Install git

$ aptitude install git-core

Setup some global info

$ git config --global user.name "My Name"

$ git config --global user.email "my@email-address.com"

Add the origin

$ git remote add origin ssh://user@server.com/var/lib/git/therepo

Now clone the repo. You can set a new repo name. If not, the remote repo name will be used to create a folder.

$ git clone ssh://user@server.com/var/lib/git/therepo [local_repo_name]

Initialized empty Git repository in /home/user/git/therepo/.git/

remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Receiving objects: 100% (3/3), done.

Adding or edit files in the local repo


Start to do some work and add them to your local repo.

$ touch testfile

$ git add testfile

$ git commit tesfile

Created commit f0ed9ad: testfile

0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 testfile

Here you added some files to the repo and commited them to your local branch - not to the remote branch! To do this step, you have to push them. Remember that we set the origin allready.

$ git push origin master

Counting objects: 3, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 247 bytes, done.

Total 2 (delta 0), reused 0 (delta 0)

To ssh://user@server.com/var/lib/git/therepo

fb17959..f0ed9ad master -> master

If you want to recieve the actual repo or just want to check if everything is update here, use git pull.

$ git pull

Already up-to-date.

That's it - have fun with git!

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