Git: Easy way to setup a private remote repository 14 comments

Posted by stephane Tue, 04 Mar 2008 19:41:00 GMT

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.git

Add this new repository in the config of your local project:

git remote add my_remote_repo ssh://server/path/to/repositories/my_project_folder.git

You’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_repo

Use 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.

Comments

Leave a response

  1. Jon Gretar about 13 hours later:

    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.

  2. Stephane about 15 hours later:

    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 :)

  3. Jon Gretar about 15 hours later:

    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. :)

  4. Stephane about 16 hours later:

    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.

  5. Chris about 22 hours later:

    How come you cloned your initial project? I usually just:

    scp -r .git ssh://remotehost:new_repo.git

    Then go from there.

  6. Stephane 1 day later:

    Ok, thanks for the comment.

    Should it even be:

    scp -r .git remotehost:new_repo.git
  7. Rich 1 day later:

    Don’t forget that your remote host has to have Git installed for this to work.

  8. Chris 1 day later:

    Yeah, it should ;)

  9. RF 1 day later:

    Jon Gretar, you should maybe checkout Mercurial (Hg), there’s even a TortoiseHg project. It’s a really great SCM (and fast)

  10. David Beckwith 7 months later:

    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?

  11. Hauptmech 8 months later:

    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!

  12. K.Shabazz 8 months later:

    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.

  13. wonderingwout 11 months later:

    Great tut. Actually exactly what I needed. For me moving to Git was a relief. But SVN never has been my best friend.

  14. kalyan about 1 year later:

    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?

Comments