Setting up a git sever

On the server:

Add a git user so that you can control access to your repo

adduser git
su git

Create an empty repo in git’s home directory using the –bare flag so that a working copy is not stored here.

cd ~
mkdir project.git
cd project.git
git --bare init

On your dev machine:

Create your project and cd into it the create the git repo without the –bare flag because you want a working copy here.

git init

Add files to your project

git add .
git commit -m 'Initial checkin'

Point the repo to the remote server

git remote add origin git@PROJECT_SERVER:project.git
git push origin master

Configure your new repo as if it was a git clone. ie git push won’t give the error,

"You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me either.  Please
name which branch you want to merge on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details on the refspec.

If you often merge with the same branch, you may want to
configure the following variables in your configuration
file:

    branch.master.remote = <nickname>
    branch.master.merge = <remote-ref>
    remote.<nickname>.url = <url>
    remote.<nickname>.fetch = <refspec>

See git-config(1) for details."
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Setup your ssh keys so you don’t need to enter a password every time and make a key if you don’t have one

ssh-keygen
#Copy the key to the git server
ssh-copy-id git@PROJECT_SERVER

If you don’t have ssh-copy-id (I had to install it on my mac) you can find it here:

http://www.chiark.greenend.org.uk/ucgi/~cjwatson/cvsweb/~checkout~/openssh/contrib/ssh-copy-id

If that did not add your key correctly you may need to run

ssh-add

I had to do that on my powerbook

Now you can have others checkout the code with:

git clone git@PROJECT_SERVER:project.git

Some people have told me that when using older versions of git the command needs to be:

git clone git@PROJECT_SERVER:~/project.git
  1. No comments yet.
  1. No trackbacks yet.