415

I am a long time Subversion user that is going to try Git. I have read some about it and understand the distributed nature - I can see a lot of the benefits.

However, I do like the idea of a central server that can take on the role of backups, system of record, etc, while still using Git for my local branching and sharing. I am not doing an open source project, so I can't use Github (without paying), so my question really is: what is a best practice way to run a local git server?

I realize this may be against the standard Git usage pattern, but it will be useful for my project. Any concerns that I may have overlooked are always welcome, however.

Thanks!

skaz
  • 21,962
  • 20
  • 69
  • 98
  • 50
    Using a centralized server as you describe it _is_ actually a standard usage pattern for distributed version control systems, so don't worry about that. :-) – Aasmund Eldhuset Mar 31 '11 at 23:22
  • 8
    Ahh - thought it was more the exception. Wanted to fend off "if you have centralization then you just don't get it!" comments. Thanks. – skaz Mar 31 '11 at 23:24
  • 27
    A reasonable thought. :-) In my understanding, the big point of distributed VCS's is not that you are supposed to not have a central repo (this is often highly useful), but rather that you _aren't forced_ to use the central repo - you can perform local commits, and it is easy to exchange revisions with specific people if need be, and you can even have several "central" repos (in git, any other repo, no matter what role it has, is called a _remote_, and you can add as many as you like). And DVCS's often have very flexible branching models (git shines here). – Aasmund Eldhuset Mar 31 '11 at 23:35
  • 15
    To summarize/rephrase Aasmund's comment: the point of a DVCS is often not to do away with the centralized repository, but to provide every single other user with the full power of the VCS as well. – Cascabel Mar 31 '11 at 23:38
  • 2
    Google has a new Cloud Source Repository which allows private repos: https://cloud.google.com/tools/cloud-repositories/ Also, FWIW, not sure why this is marked as off topic! – Josh M. Jun 26 '15 at 10:53
  • 1
    You can use GitHub, Now , Supports Private Repos – PurTahan Jan 20 '19 at 07:48

19 Answers19

202

You can just set up an ssh server and run a central repository there. All developers then simply agree (as a matter of policy) to push to the server when they are done making commits. This is the usage pattern at my workplace. Very CVS and SVN-like.

  1. Find somewhere to put the repository (/var/gitroot for example).
  2. Create a new repo (mkdir project.git && cd project.git && git init --bare --shared=group).
  3. Then on your client, clone the remote repo (git clone ssh://yourserver.com/var/gitroot/project.git && cd project)
  4. add some files (git add README)
  5. commit (git commit -m "Initial import"),
  6. push (git push origin master)

This should set things up for you.

endolith
  • 25,479
  • 34
  • 128
  • 192
Chris Eberle
  • 47,994
  • 12
  • 82
  • 119
  • 5
    Just so I am clear: Install git on another (accessible) server and create a repo. Have clients clone that repo. When a client completes a fix, push up to the server repo. Thanks! – skaz Mar 31 '11 at 23:25
  • 8
    +1. As a matter of fact, this is _the_ usage pattern for collaborative use of git. – Aasmund Eldhuset Dec 11 '12 at 14:39
  • 1
    This error happened when push the origin master:::: Counting objects: 3, done. Writing objects: 100% (3/3), 244 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: error: insufficient permission for adding an object to repository database ./objects remote: fatal: failed to write object error: unpack failed: unpack-objects abnormal exit To ssh://localhost/var/gitroot/project.git ! [remote rejected] master -> master (unpacker error) error: failed to push some refs to 'ssh://localhost/var/gitroot/project.git' – Abdo May 26 '14 at 18:12
  • 3
    I've wrote a [blog post](http://www.convalesco.org/articles/2009/07/24/how-to-set-up-a-personal-git-repository-in-10-minutes/) about how to setup a local git repo some time ago. It's 10 minutes max. The hard thing is setting proper local-server backup strategies, administrating the server, etc. – patm Jun 25 '15 at 05:24
  • Can't you just run `git init --bare project.git` ? – Dan Dascalescu Jan 26 '17 at 07:30
  • Didn't know you could git over ssh, adding `ssh-copy-id` with password less login makes this an unbelievable simple solution that actually takes less than a minute form the google search to updating the repo. Took a minute more to set some permission to existing devs on the home network and was back to coding in less time i took to write this comment. – Louis Loudog Trottier Jun 09 '18 at 01:35
  • Can you make a user:password instance of git available to everyone and not have to use ssh? – Edward Kennedy Mar 21 '19 at 16:58
  • @patm no post anymore :( was it deleted or moved? – smsware Nov 20 '22 at 14:43
  • 1
    @smsware here: https://www.convalesco.org/notes/2009/07/24/how-to-set-up-a-personal-git-repository-in-10-minutes.html – patm Nov 21 '22 at 15:32
199

Gitorious is an open source web interface to git that you can run on your own server, much like github:

http://getgitorious.com/

Update:

http://gitlab.org/ is another alternative now as well.

Update 2:

Gitorious has now joined with GitLab

Craig
  • 7,471
  • 4
  • 29
  • 46
  • 5
    Looks nice, but the setup seems heavy-weight (esp. for a non-rails user) [ http://cjohansen.no/en/ruby/setting_up_gitorious_on_your_own_server ] – gatoatigrado Nov 30 '12 at 01:39
  • 1
    The installation process is in the process of being heavily simplified and made less "Rails-y". There's also an automated installer for CentOS servers (and a prebuilt appliance) available at the [Install Gitorious](http://getgitorious.com/install-gitorious) page at getgitorious.com. – thomanil Jan 11 '13 at 08:27
  • 3
    It seems that Gitorious is no longer a free open source private hosting solution. – Mingming Apr 02 '13 at 12:38
  • 1
    If you go to http://getgitorious.com/ and click Installer under Gitorious Community Edition does that not give you a free open source private hosting solution? – Craig Apr 02 '13 at 16:39
  • 16
    Also http://gitlab.org/ is another alternative that has been developed since my answer. – Craig Apr 02 '13 at 16:42
  • 1
    try [gogs](http://gogs.io/) , it is better to setting. – plan9assembler Nov 22 '14 at 09:57
  • 1
    Both Options Are Sellouts, way to go "free open source solutions"... – NinjaKC Sep 11 '15 at 00:27
  • For GitLab, if I need to version control my thesis, which contains my latex report and code, should I create a Group with two separate projects (code and latex) or should I create one repository called thesis with two directories in the root (code and latex)? – Jim Feb 02 '16 at 16:42
  • 1
    @Jim Both could have benefits. But that is off topic for this question. You could ask your adviser, or ask a question on http://academia.stackexchange.com/ – Craig Feb 02 '16 at 16:49
  • getgitorios.com now present a generic parked domain page. But here's this page `https://about.gitlab.com/installation/` with links to installers for so many platforms? Is it still open source? What's the license? . . . – Alex Hall Jan 03 '18 at 21:40
75

Try GitLab

The best git GUI tool i have ever used. It is very similar to GitHub.

It is open source (MIT License) and is the most installed git management software with over 25.000 installation. It has monthly releases and an active community with over 375 contributors. You can have unlimited private, internal and public repositories on your own server. It is a Ruby on Rails app that runs on most Unix platforms.

Sytse Sijbrandij
  • 1,885
  • 2
  • 22
  • 20
Plamen Nikolov
  • 4,177
  • 3
  • 23
  • 24
  • 1
    I agree, it's awesome. (+1) But as of this comment it's a pain to install. It would be great if they could package rpm, deb etc. – Synesso Jan 06 '13 at 05:58
  • 2
    I've found the relatively new single script setup for Ubuntu to be pretty pain free. Even without it it's mostly a matter of following the instructions off the site. I've never used rails or really even Ubuntu server and I got it running first try. – Jon Shier Feb 12 '13 at 20:20
  • I experienced some trouble integrating it with Active Directory via LDAP. – riezebosch Jan 09 '14 at 13:37
  • 2
    Actually, nowadays GitLab is pretty easy to install. It's just a matter of unpacking a package. See about.gitlab.com/downloads – Job Jan 18 '15 at 06:36
  • Its not for windows. :( –  Jul 17 '15 at 15:57
  • https://about.gitlab.com/pricing/ <--- Not Free... – NinjaKC Sep 11 '15 at 00:28
  • 2
    Gitlab Enterprise is not free of course, but there is [community edition](https://about.gitlab.com/downloads/), which is free and also easy to install. Although, it requires around 800 MB of disk space, as it installs couple of database engines and lots of dependencies. – OndroMih Jan 22 '16 at 18:49
38

If you don't mind getting down and dirty with the command line, gitolite is an absolute treat when working in a corporate environment where you need to set differenct access rights on different repositories. It is sort of a newer version of gitosis mentioned by @Chris.

Here is the summary from the author's web site:

Gitolite lets you use a single user on a server to host many git repositories and provide access to many developers, without having to give them real userids on or shell access to the server. The essential magic in doing this is ssh's pubkey access and the authorized_keys file, and the inspiration was an older program called gitosis.

Gitolite can restrict who can read from (clone/fetch) or write to (push) a repository. It can also restrict who can push to what branch or tag, which is very important in a corporate environment. Gitolite can be installed without requiring root permissions, and with no additional software than git itself and perl.

It has quite a comprehensive feature set, but one thing I like very much, is that all of the day to day configuration editing is done through a special git repository. That is, adding a user is just

  • Add user to configuration file
  • Add the user's ssh key
  • Commit the change
  • Push it to gitolite
  • Voila, the configuration is live!

And when needing to look at the code through browser, gitolite has support for "syncing" configuration with gitweb. Or if you like cgit, which is a very good web frontend for git written in C, better, then you should look at this how-to.

Community
  • 1
  • 1
stigkj
  • 1,439
  • 14
  • 10
24

You might consider Gitblit, an open-source, integrated, pure Java Git server, viewer, and repository manager for small workgroups.

James Moger
  • 1,721
  • 12
  • 12
  • Gitblit seems perfect for my application, but it worries me that the last release was in 2016. – Yogi Apr 25 '19 at 12:03
  • 1
    @Roberto, a valid point. I guess it depends on what you need or what is important to you. If it works for you as it is, it could still be a valid choice. If you are worried about timely bug fixes or need more features, it might not. – Florian Nov 14 '19 at 10:19
15

Bare Bones Browser

git instaweb --httpd=webrick

from the git scm book

combine it with something like the approach described here for distributed development (credit to datagrok for the well described concept)

Launch a one-off git server from any local repository.

I tweeted this already but I thought it could use some expansion:

Enable decentralized git workflow: git config alias.serve "daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/"

Say you use a git workflow that involves working with a core "official" repository that you pull and push your changes from and into. I'm sure many companies do this, as do many users of git hosting services like Github.

Say that server, or Github, goes down for a bit.

No worries, after all, one of the reasons you use git is so you have a copy of the entire project history in your local clone.

You can keep right on coding and committing, while you wait for the operations team to bring the server back to life. Note to self: buy doughnuts for operations team.

But what if, during this downtime, you want to collaborate with another person, who may not be a git expert, on the same repository?

Or, instead of downtime, what if you and your collaborator are in the field, and for some reason you can't get your VPN to let you connect to your official repo?

Or, what if you and your collaborator are spiking out a bunch of experimental changes, and even though you have access, you don't want to push your unfinished mess into the official central repository? (Not even as feature branches.) Maybe you're in the middle of cleaning up a disastrous rebase or merge and the branches are all over the place.

Well, git, as you are probably aware, is a "distributed" version control system.

Even though you might use a central "official" git repository in your workflow, you still have the ability to use git in a peer-to-peer manner, where you and your collaborator simply build and share commits with each other, and the central server never even has to know.

So, how do you get your branches and commits over to them, or vice versa?

  • You could use git's facilities for e-mailing patches. But that's a bit inelegant and requires some knowledge on their end of how to apply e-mailed patches.
  • You could create an account on your own machine for your collaborator to ssh into. But maybe you don't have local root access, or maybe you don't trust them with SSH access to your box.
  • You could clone your repo onto a thumbdrive and pass it back and forth. But that's rather tedious, especially if you happen to be on the same local network, and requires a thumb drive.

You can probably think of other methods, too. But there's a super easy way: if you can see each other on the network, you can launch a one-off git server that they can use as their remote to clone, fetch, and pull your changes, and kill it when you're done with it.

The tool that enables this is git daemon, which has a lot of options and functionality, but for the purpose of enabling this easy one-off "just serve up the repo I'm in," the way to use it is to create an alias. I like to call it git serve. Run:

git config --global alias.serve "daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/"

Using an alias is actually crucial, because git aliases are executed in the base directory of your working tree. So the path '.git' will always point to the right place, no matter where you are within the directory tree of your repository.

Use your new git serve like so:

  1. Run git serve. "Ready to rumble," it will report. Git is bad-ass.
  2. Find out your IP address. Say it's 192.168.1.123.
  3. Say "hey Jane, I'm not ready/able to push these commits up to origin, but you can fetch my commits into your clone by running git fetch git://192.168.1.123/"
  4. Press ctrl+c when you don't want to serve that repo any longer.

You could also tell Jane to git clone git://192.168.1.123/ local-repo-name if she does not yet have a clone of the repository. Or, use git pull git://192.168.1.123/ branchname to do a fetch and merge at once, useful if you are working together on a feature branch.

Note however that you shouldn't do this on hostile networks if you keep secrets in your repository, because there's no authentication. It doesn't advertise its existence, but anybody with a a port scanner can find it, connect to it, and clone your repo.

But it's not super dangerous because it is read-only by default. Read the git daemon man page carefully if you think that you want to enable write access. In the case where you want to obtain your collaborator's commits, it's much safer to leave it read-only, and ask your collaborator to also run this command, so you can pull from them.

Tangentially related: on the subject of one-off servers, if you want to temporarily share a bunch of static files over HTTP: python -m SimpleHTTPServer

shaedrich
  • 5,457
  • 3
  • 26
  • 42
Mark Essel
  • 4,606
  • 2
  • 29
  • 47
11

If you need good, easy GIT server than you must try GitBlit. Also i use gitolite but it only server, with GitBlit you get all in one, server, admin, repos. manager ... URL: http://gitblit.com/

corysus
  • 647
  • 9
  • 12
9

https://rhodecode.com is an open source web app for Git & Mercurial which can be very easily installed under any operating system (an installer is included).

RhodeCode (the new version is called RhodeCode Enterprise) adds missing Git features like code review and it is generally speaking very fast and reliable.

Sebastian
  • 8,952
  • 3
  • 32
  • 30
  • 1
    I actually run my own instance here: http://code.gmgauthier.com/. The 3.x release is remarkably clean and stable. I use it for much more than code, actually (though, there is plenty of that up there). I use it to keep master copies of my personal journals, manuscripts for two books, podcast scripts, and blog drafts. It's ideal for this, partly because it renders both Markdown and RestructuredText for you, making the drafts very readable from anywhere. – Greg Gauthier Aug 26 '15 at 06:59
8

It may not be the most common git server setup, but having played with different layouts, tools, mirroring and permission schemes, I'd say one pretty solid alternative for enterprise repositories is Gerrit, which may seem surprising as it is more known as a code review tool. We started using it as code review and it slowly became our main repository, deprecating g3/gitolite

  • It is straightforward to deploy (you basically drop the .war in a tomcat)
  • has a web ui to manage repositories, groups and permissions (or a ssh cli)
  • has a built-in java ssh and git implementation, so you have nothing else to set up
  • ldap support for users and groups (usually a must for companies)
  • a very flexible permission system (with project groups, permission inheritance, restricting read/write/branching/unreviewed writes/etc)
  • code review capabilities (if you're into that thing)
  • repo mirroring (to push some repositories to github or other public repo)

In addition, it's used by large projects (e.g. android, chrome) so it does scales and is now fairly solid. Just give your users the PUSH permission if you want to allow bypassing the code review part.

simpoir
  • 211
  • 3
  • 9
8

You can even install GitHub on your local server (but not for free):

https://enterprise.github.com/

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
8

You can also install Indefero, it is a GPL clone of GoogleCode, as it supports both Subversion and Git, you can have a smooth transition. I am the author of Indefero.

7

For a remote hosting As others have said bitbucket.org offers free private repositories, I've been using it without problems.

For local or LAN network I will add this one scm-manager.org (A single executable file, is really simple to install, it's made on Java so it can run on Linux or Windows). Just in case you install it, these are default passwords.

Username: scmadmin
Password: scmadmin
Hernán Eche
  • 6,529
  • 12
  • 51
  • 76
6

In the meantime, the Mercurial hosting site Bitbucket has started to offer Git repositories as well.

So if you don't need a local server, just some central place where you can host private Git repositories for free, IMO Bitbucket is the best choice.

For free, you get unlimited private and public Git and Mercurial repositories.
The only limitation is that in the free plan, no more than five users can access your private repositories (for more, you have to pay).
See https://bitbucket.org/plans for more info!

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
4

If you want pull requests, there are the open source projects of RhodeCode and GitLab and the paid Stash

joedborg
  • 17,651
  • 32
  • 84
  • 118
2

If you just want your repository in a central place, this is quite easy with distributed version control like Git:
You can just put your central repository in some shared folder on a central machine and everybody can clone it from there.

If you want a "real" website on your local server, I know of the Git hosting website http://repo.or.cz.
It seems to have less features than GitHub, but unlike GitHub, you can get the source code and host it on your own local server.

Disclaimer: I only read about repo.or.cz, I never tried it myself!

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
2

for simple setups, you can provide ssh access to a central server, and set up each user's working directory to push/pull from this 'origin'. That would be the most simple and common setup for small teams.

You might also look into gitosis which gives you an http server and the ability to manage it remotely. That way you don't have to grant ssh access and all that entails to each committer.

sbeam
  • 4,622
  • 6
  • 33
  • 43
2

To add to what Chris has said, you can use gitosis (http://eagain.net/gitweb/?p=gitosis.git) to control who can actually access the repo.

Depending on your usage, you can also use hooks (in the .git/hooks folder) so that your code will automatically be pulled into the server's filesystem when you push from your local machine. Here's a popular script for doing that: http://utsl.gen.nz/git/post-update. This won't be necessary in all cases though.

liamacheung
  • 169
  • 1
  • 4
  • 9
1

http://repo.or.cz, while fairly good tends to have some issues with some users.

If you are one of them I recommend that you try out http://unfuddle.com since you come from a subversion background.

Check out "The 30 Second Tour": http://unfuddle.com/about/tour/plans

Secko
  • 7,664
  • 5
  • 31
  • 37
1

http://code.google.com/p/luna-tool/ is scala application which implements most of needed for me parts of github

den bardadym
  • 2,747
  • 3
  • 25
  • 27