How to setup a git server

Source: Internet
Author: User

Ext.: http://my.oschina.net/fgq611/blog/157653

Catalogue [-]

    • 1. Erecting a git server
    • 2. Build Gitweb
    • 3. Send mail notification after push
    • 4. Reference links

In the process of development often need a git server to manage and save code, how to set up a git server, the method is very simple, here is how to set up a git server, build gitweb and push code after sending email notification group members.

1. Erecting a git server

Let's take Ubuntu for example. First, create a user named ' Git ' on the GIT server and create an. SSH directory for it. and set its permissions to only git users who have read and write permissions

sudosumkdir . SSH  chmod . SSH

Next, add the developer's SSH public key to the user's Authorized_keys file. Let's say you received a couple of public keys by e-mail to coexist in a temporary file. Again, the public key looks something like this:

cat /tmp/id_rsa.john.pubssh-rsa aaaab3nzac1yc2eaaaadaqabaaabaqcb007n/ww+  oun4gslkssmxxnbovf9lgt4lojg6rs6hpb09j9r/t17/x4lhja0f3fr1rp6kybrswj2athgw6hxlm9/5zytk6ztg3rpkk+  4kyjh6541nysneazuxz0jttyaufrtu3z5e003c4oxoj6h0rfif1kki9maqlmdpgw1gyeigs9ezsdfd8acciictdwbqlacu4upkax8kygllwsnuugztobf8m72 ALC/nlf6jltpofwfblgc+  Myivo7tcusbdlqlgmvofq1i2upwqokowqahukeomfjy2jctxsdbq220ymjansht4kgtzg2ayygpqdav8jggjicuvax2t9va5 GSG- KeyPair

Just append them to the end of the Authorized_keys file one at a time, and set Authorized_keys to only the GIT user has read and write permissions.

cat /tmp/id_rsa.john.pub >> ~/. ssh/cat /tmp/id_rsa.josie.pub >> ~/. ssh/cat /tmp/id_rsa.jessica.pub >> ~/. ssh/chmod ~/. ssh/authorized_keys

You can now run git init with the--bare option to create a bare repository, which initializes a repository that does not contain a working directory.

$ cd/opt/mkdir--bare Init

At this point, Join,josie or Jessica can add it as a remote repository and push a branch to upload the first version of the project file to the repository. It is important to note that each time you add a new project, you need to log into the host through the shell and create a bare repository directory. We might as well use gitserver as the hostname of the GIT user and project repository. If the host is running inside the network and you set Gitserver to that host in DNS, the following commands are available:

' Initial Commit ' $ git Remote add origin [email protected]:/opt/git/project.git$ git push Origin master

In this way, the cloning and pushing of other people are just as simple:

$ git clone [email protected]:/opt/git/'fix for the README file'$ git push origin Master

Using this method, you can quickly set up a read-write Git service for a few developers.

As an extra precaution, you can limit the range of activities that GIT users have by using the Git-shell tool that comes with git. As long as it is set to the GIT user login shell, then the user will not be able to use the normal bash or csh what shell program. Edit/etc/passwd File:

sudo vim/etc/passwd

At the end of the file, you should be able to find a line like this:

Git:x:£ º:/home/git:/bin/sh

Change the bin/sh to/usr/bin/git-shell (or use which git-shell to see its actual installation path). The line is modified to look like this:

Git:x:£ º:/home/git:/usr/bin/git-shell

Now git users can only use SSH connections to push and get the Git repository, rather than using the host shell directly. If you try a normal SSH login, you will see the following rejection message:

SSH Do you think I am? A Shell? Connection to Gitserver closed.

The method provided here is that all members of the group have read and write access to project, which means that each branch can push the code, and if more granular permission control is required, use gitosis or Gitolite.

2. Build Gitweb

After installing Gitweb, we can access our project through the website. Just like http://git.kernel.org.

The first need to install Gitweb, if not installed Apache, then directly installed Gitweb, will also be apache2 installed.

sudo Install gitweb apache2

After the installation is complete, we only need to modify the configuration file to change the $projectroot in the/etc/gitweb.conf file to the directory where the project files are placed.

$ vim/etc/gitweb.conf# path to git projects (<project>"/opt/git";

At this point gitweb is ready to use and can now be accessed through Http://[git_server_ip]/gitweb.

3. Send mail notification after push

When a group member push code is sent to the server, it automatically sends the message to notify all the people in the group what the specific content of the push is. Specific configuration method:

Typically, when you install Git, the script that sends the message/usr/share/git-core/contrib/hooks/post-receive-email already exists, first to modify the owner and execute permissions, and to install SendMail.

sudo chown git:git post-receive-sudochmod755 post-receive-   sudoinstall sendmail

Then, to switch to hooks in the project directory, add post-receive soft links to/usr/share/git-core/contrib/hooks/post-receive-email.

$ cd/opt/git/project.git/ln -s/usr/share/git-core/contrib/hooks/post-receive-email post-receive

Finally, you can modify the config file in the project catalog. Mailinglist is the mailing list, Envelopesender is the sender's mailbox,

$ vim/opt/git/project.git/Config[core] Repositoryformatversion=0FileMode=trueBare=true[hooks] mailinglist="[email protected], [email protected]"# recipient List Envelopesender=[email protected] # Sender address Emailprefix="[Project commit]"# message header prefix Showrev="git show-c%s; Echo"# Not only shows changed files, but also shows the changed content

In order to make the message clearer, but also to modify the project directory in the description file, in the description file, the default first line is the project name, so in the first line to fill in the name of the project, this will be displayed in the message.

$ vim/opt/git/project.git/descriptionproject_a

The title of the email we received is this:

[Project commit] Project_a Branch Master updated. 8811b83e1afb373cbe30d5bc25683d74ace2917c

Sometimes we will find that start and send sendmail are quite slow, even to wait two or three minutes, completely can not endure, finally through continuous testing, solve the problem, mainly to modify the/etc/hosts. For example, my sender's domain is Example.com,hostname is desktop, so this should be modified:

127.0. 0.1  example.com localhost desktop

Restart the SendMail service after the change is completed:

Service SendMail Restart

Then you will find that the mail is sent by the brush drop!

At this point, our git server has been set up, and your small partner happy coding it!

4. Reference links

Http://git-scm.com/book/zh/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E6%9E%B6%E8%AE%BE%E6%9C%8D%E5%8A%A1%E5%99%A8

http://josephj.com/entry.php?id=346

How to setup a git server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.