Git: Easy way to setup a private remote repository 15 comments
Git is different from svn and create a private repository on a remote server too. No need of gitosis or git-daemon for this.
I start from an existing project and a server I already access to with ssh key.
First, initialize git in your project:
git init
git add .
git commit -m 'initial import'[update]
Then create a git copy of your project into a git archive my_project_folder.git.
git clone—bare my_project_folder my_project_folder.git
Copy this archive the .git folder to your remote server:
scp -rp .git user@server://path/to/repositories/my_project_folder.gitAdd this new repository in the config of your local project:
git remote add my_remote_repo ssh://server/path/to/repositories/my_project_folder.gitYou’re done. After a change you can commit and then push your change to the remote repo:
git commit -m "message for change log"
git push my_remote_repoUse your own parameters for:
- my_project_folder with the folder of your project
- path/to/repositories with the path to your repository on the remote server
- my_project_repo with the name you want for the remote repository, usually origin
If you need a public repository, have look to gitosis or git-daemon. Best is Github.





Call me old fashioned…. But I still haven’t found any reason for why I should move to git from Subversion. I have no need for local repos since I’m always network connected. The easy branching would be nice but really isn’t a must for me. But I would miss all the tools that would be missing.
And I keep hearing about how amazing it is to have many repositarys for the code. But I haven’t really heard why it would be an advantage. Unless you have 20+ developers on the project working on the same code. And that’s not common.
This post is more about using git than moving from svn to git. But for my own experience, I did move to git because it’s much faster and open new ways of social collaboration, as you can see on Github. Also I’d prefer to make several local commits and then a bigger commit to a central repo rather than always push small changes to the repo, and I m not always connected. A last point, git is pretty well integrated in Textmate now.
Being said, people are free to use whatever SCM they like :)
Hey I’m not judging. ;)
After watching the Peepcode screencast I decided not to go to Git. Just seemed to overly complicate things somehow when most users just simply need to know the “svn add” and “svn commit” commands and they are good for life. :)
You’re right, the learning curve is harder with git than with svn and for new users it’s not simplifying life, at first. That’s why I published this post to show an “easy” way of using git. Currently I only use clone, commit, and push.
How come you cloned your initial project? I usually just:
scp -r .git ssh://remotehost:new_repo.git
Then go from there.
Ok, thanks for the comment.
Should it even be:
scp -r .git remotehost:new_repo.gitDon’t forget that your remote host has to have Git installed for this to work.
Yeah, it should ;)
Jon Gretar, you should maybe checkout Mercurial (Hg), there’s even a TortoiseHg project. It’s a really great SCM (and fast)
Git is simply way faster than SVN. Just for the upload and synchronization time that I save, I would switch from SVN to GIT. But that’s not all! In addition Git makes branching and merging very fluid. In short, Git makes your more agile! And we all want that don’t we? Or do we like to stagnate?
Stephane, Thanks for this post. I was pulling my hair out looking at the git-daemon docs when all I wanted to do was this. Cheers!
I’m also trying to setup a Git repo for remote access. However, I’m on windows :( Thank goodness for msysGit, but I don’t see that git-daemon is supported yet on msysGit. I will try to setup ssh on one machine (with git and the repository) and connect to it with git from another PC. If I’m able to do that then we may be in business of switching things at work. Well maybe when more VS tools become available :(
If anyone can point me in the right direction would appreciate it.
Everywhere I go, I see someone trying to push Mercurial on new git user.
Great tut. Actually exactly what I needed. For me moving to Git was a relief. But SVN never has been my best friend.
Hi… that was great stuff.. I really like reading on this subject Could you tell me more on that… I love to explore
Thanks for the post. This works perfectly. What if i create a new branch on my desktop? How do I pull it to the remote, any idea?