Git'n Your Shared Host On
GitHub is awesome, really awesome for open source projects and for projects with multiple people. In fact, if you use your own git setup for an open source project, you are most likely hindering your project’s progress and wasting your time.
On the other side of the coin, if you are a lone shark and you don’t need GitHub’s awesome social features, I have news for you: you can host your own git repositories really easily and on the cheap side.
If you are like me, you probably have a DreamHost, TextDrive or some other cheap shared hosting account with ssh access. What you might not know is that is all you need to host your own private git repositories.
ssh email@example.com mkdir -p ~/git/yourproject.git cd ~/git/yourproject.git git --bare init
That is it. Your git repository is now setup. Not too hard eh? You could put that anywhere but a folder named git makes sense to me.
So your remote server is now setup, but how do you use it? Glad you asked. Open up a new tab (or window) or quit your ssh connection and cd to wherever you want to setup your project locally.
mkdir yourproject cd yourproject git init git remote add origin ssh://firstname.lastname@example.org/~/git/yourproject.git touch .gitignore git add . git commit -m "Initial Commit" git push origin master
At this point you have now pushed to your remote repository and are almost good to go. The last thing is you need to add the following on your local machine to .git/config in your project.
[branch "master"] remote = origin merge = refs/heads/master
That is it. You can now push and pull at will. If you want to give anyone else commit access, just add their ssh key to ~/.ssh/authorized_keys and you can work on the project with a friend. Setting up your own git repositories is really easy, as you can see, so don’t be afraid.
So what I showed above is really the most basic setup you can have. It involves pushing and pulling using ssh and is easy peasy. If you want more than that, such as finer grained access control, enjoy the following links.
Casper Fabricius wrote a handy shell script that allows doing all that I mentioned above on DreamHost in one easy terminal command.
Rick Olson has an article on moving to git where he shows a rake task he used and also links to gitosis.
Speaking of gitosis, Garry Dolly has an article on setting up gitosis and how to add users and manage their repository permissions.
Tim Lucas has a good post on setting up a new remote git repository.
GitHub has a ridiculous number of guides that are geared towards using GitHub but have morsels handy for non-GitHub usage.
Happy, cheap git hosting!