Host your own private git repository via SSH

Posted by kerry on Gooder Code See other posts from Gooder Code or by kerry
Published on Sat, 14 May 2011 21:46:54 +0000 Indexed on 2011/06/20 16:36 UTC
Read the original article Hit count: 496

Filed under:
|
|

If you are like me you have tons of projects you would like to keep private but track with git, but do not want to pay a git host for a private plan. One of the problems is that most hosts scale their plans by project instead of users. Luckily, it is easy to host your own git repositories on any el cheapo host that provides ssh access.

In the interest of full disclosure, I learned this trick from this blog post. I decided to recreate it in case the source material vanishes for some reason.

To setup your host, login via ssh and run the following commands:

mkdir ~/git/yourprojectname.git
cd ~/git/yourprojectname.git
git --bare init

Then in your project directory (on your local machine):


# setup your user info
git config --global user.name "Firstname Lastname"
git config --global user.email "[email protected]"

# initialize the workspace
git init
git add .
git commit -m "initial commit"
git add remote origin ssh://[email protected]/~/git/yourprojectname.git
git push origin master

It’s that easy!

To keep from entering your password every time add your public key to the server:

Generate your key with ‘ssh-keygen -t rsa‘ on your local machine.  Then add the contents of the generated file to ~/.ssh/authorized_keys on your server.

© Gooder Code or respective owner

Related posts about Developer Tools

Related posts about git