|
Setting Up a Git ServerWritten By: Ben Wyrosdick April 13th, 2008 |
Setting up a remote git server is as easy as setting up a new user. In fact if you have git installed on the machine that is about all you need to do. We will not discuss setting up git … just how to set it up to be used as a remote repository.
First we need to setup a user with a home folder. We will store all the repositories in this users home folder.
sudo adduser git
Rather than giving out the password to the git user account use ssh keys to login so that you can have multiple developers connect securely and easily.
Next we will make a repository. For this example we will work with a repository called example. Login as the user git and add the repository.
# login to remote server ssh git@REMOTE_SERVER # once logged in mkdir example.git cd example.git git --bare init
That’s all there is to creating a repository. Notice we named our folder with a .git extension.
Also notice the ‘bare’ option. By default the git repository assumes that you’ll be using it as your working directory, so git stores the actual bare repository files in a .git directory alongside all the project files. Since we are setting up a remote server we don’t need copies of the files on the filesystem. Instead, all we need are the deltas and binary objects of the repository. By setting ‘bare’ we tell git not to store the current files of the repository only the diffs. This is optional as you may have need to be able to browse the files on your remote server.
Finally all you need to do is add your files to the remote repository. We will assume you don’t have any files yet.
mkdir example cd example git init touch README git add README git commit -m 'first commit' git remote add origin git@REMOTE_SERVER:example.git git push origin master
replace REMOTE_SERVER with your server name or IP
May 5th, 2008 at 02:33 PM This is awesome. Setting up a git server was something that I thought was going to require a ton of emails here at my company. This is so simple that I can do this on one of our sandboxes without even bothering any of the admins. Nice!
June 11th, 2008 at 07:46 PM I also thought it much harder, and I'm glad I was proven wrong. You can do it the same way with Mercurial by just replacing "git" with "hg" :) Still it's a bit behind the extreme ease with which I can serve a repository via Mercurial, if I only want to provide my changes to others without much overhead: $ hg serve Serves my repository from my local machine at port 8000. $ hg serve -p PORT -n NAME uses a different port and gives the repository a name (It's only a subset of the options, but the most useful, I think :) ).
June 27th, 2008 at 07:27 PM you should add a '--bare' to 'git init', when you set up the repo on the server
June 29th, 2008 at 01:13 AM You could add that and it would save you a little bit of disk space. I can't find it in the man page but I have read explanations online of how --bare works. I will update the post.
September 8th, 2008 at 12:17 PM Very, very helpful post. Thanks alot!
September 11th, 2008 at 02:06 PM Excellent tutorial! Simple and to the point.
September 14th, 2008 at 03:01 AM Really nice. this is much easier then setting up gitosis.
November 4th, 2008 at 01:58 PM @Arne: the counterpart to `hg server` in the git world is `git-daemon`. It starts a simple daemon on well known git port 9418 and serves the repository.
December 3rd, 2008 at 01:34 PM Thanks for the post. This helped me out.
December 16th, 2008 at 07:31 PM To the point and easy. Thank you
January 23rd, 2009 at 09:47 AM Great mini-guide! Before finding this page, I thought setting up and serving a remote Git repository was much more complicated. This really got me started using Git.
February 12th, 2009 at 05:41 AM Good guide - finally got over the --bare bit with your help!
February 19th, 2009 at 02:38 PM Thanks, I thought it should be something like this and I'm glad I wasn't mistaken.
February 20th, 2009 at 05:44 PM Thanks a lot! That took all of 30 seconds. I would describe what "origin" means though.
April 3rd, 2009 at 04:33 PM Excellent! Thanks, helped a lot!
April 21st, 2009 at 07:57 PM Great instructions! I was expecting this to be a big pain, but I got done quickly. Thanks.
June 11th, 2009 at 03:04 PM Then the question is just to get "git 4.x" to work just as smooth.. A lot of us are forced to use this old version because the dreambox repository does not compile on anything newer (debian platform).
July 7th, 2009 at 05:31 PM "Rather than giving out the password to the git user account use ssh keys to login so that you can have multiple developers connect securely and easily." this means everyone pushes changes under the 'git' user ? what if fred changes his .gitconfig file to set his name to david: will he be able to push under david and no one knows it ?! cheers
July 11th, 2009 at 07:57 PM Very handy! Good man. :)
July 16th, 2009 at 10:18 AM Nice howto. However, if you need user management und secure datatransfer gitosis is the way to go. http://sunoano.name/ws/public_xhtml/scm.html#provide_a_git_repository_to_the_public
August 14th, 2009 at 04:19 PM What if you want to start keeping a remote copy of a repository that already exists on your local machine?
September 1st, 2009 at 06:45 AM Thanks for this Document! But When I am going to Push.. its showing error like this: "fatal: I don't handle protocol 'git@192.168.1.3'". Whatz the reason for getting this error. But I'm able to do all works on GIT Repo. except this PUll PUSH and CLONE. Suggest me what I'm wrong. Thanks in Advance!
October 10th, 2009 at 11:28 AM the best and simplest guide i have found, THANKS
October 14th, 2009 at 01:18 PM Just wanted to add my thanks too! I'll just re-iterate what so many others have already said: this is by far the best guide to getting a simple Git server up and running. I've tried other guides (gitosis, WebDAV, etc...) and just failed at getting them to work. Your guide just took one minute, if that!
November 6th, 2009 at 03:49 AM Wow this was so unbelieveably simple. Thanks a million times.
November 23rd, 2009 at 09:04 PM Well done!
January 22nd, 2010 at 05:19 PM "Notice we named our folder with a .git extension." It looks like it's not necessary to actually name your folder "bla.git". Instead you can just point to the .git folder within your desired folder, so like: git remote add origin git@your-server:your-folder/.git