Git Server Configuration

Source: Internet
Author: User

Git server build up

The task was started a few days ago, although the server is still in the procurement process. But it has already been built on a PC for internal group testing. Record the process here:

Hardware requirements: a Linux computer with an independent IP address under the company's LAN, and ensuring that everyone in the group can ping;
Software requirements: Git-core, gitosis, OpenSSH-server, OpenSSH-Client

Install git and OpenSSH:
$ Sudo apt-Get install Git-core openssh-server openssh-Client

The newly added git user will act as the administrator of all code repositories and user permissions:
$ Sudo useradd-M git

Set a password for git:
$ Sudo password git

To create a git repository storage point, I put it under/opt/git, And let users other than git have no permission for this directory:
$ Mkdir/opt/git
$ Sudo Chow git: git/opt/git
$ Sudo chmod 700/opt/git

Initialize the GIT user on the server. This step is actually to prepare for installing gitosis. Of course, if you use git on any machine, you must initialize it for the first time, git has never had the "well-known and non-existent" set:
$ Git config -- global user. Name "name"
$ Git config -- global user. Email "myemail"

Install the python setup tool to prepare for gitosis:
$ Apt-Get install Python-setuptools

Get the gitosis package:
$ CD/tmp
$ Git clone git: // eagain.net/gitosis.git
$ CD gitosis
$ Sudo Python setup. py install

Switch to the GIT User:
---------------------------
$ Su-Git

By default, gitosis stores the GIT repository in the home of the GIT user, so we make a link to/opt/git
$ Ln-S/opt/git/home/git/Repositories
$ Exit
Return to the default user again.

If you want to act as the GIT server administrator, generate an SSH public key on your computer:
$ Ssh-keygen-T RSA

Copy the public key to/tmp and grant the read permission to others:
$ CP ~ /. Ssh/id_rsa.pub/tmp & chmod A + R/tmp/id_rsa.pub

Run gitosis:
$ Sudo-H-u git gitosis-init </tmp/id_dsa.pub
Initialized empty git repository in/opt/git/gitosis-admin.git/
Reinitialized existing git repository in/opt/git/gitosis-admin.git/

What's interesting about gitosis is that it manages configuration files through a git repository and stores them in/opt/git/gitosis-admin.git. We need to add executable permissions to a file:
$ Sudo chmod 755/opt/git/gitosis-admin.git/hooks/post-Update

We have created an empty project warehouse on the server for testing. I have created a warehouse named "teamwork.
Switch to git User:
$ Su-Git
$ CD/opt/git
$ Mkdir teamwork. Git
$ CD teamwork. Git
$ Git init -- bare

Clone the gitosis-admin.git repository on your computer so that you can modify the configuration as an administrator.
In your computer:
$ Git clone git @ Git-server-IP: gitosis-admin.git
$ CD gitosis-Admin

Now we will take all the SSH public key files of all of your team and name them by name, for example, Kevin. Pub, Cindy. Pub, Peng. Pub, and so on, and copy them all to the keydir:
$ CP ~ /Kevin. Pub ~ /Cindy. Pub ~ /Peng. Pub keydir/
Modify the gitosis. conf file. My configuration is roughly as follows:
[Gitosis]

[Group gitosis-admin]
Writable = gitosis-Admin
Members = volans

[Group team]
Writable = teamwork
Members = volans Kevin Cindy

[Group team_ro]
Readonly = teamwork
Members = Peng
This configuration file expresses the following meanings: The gitosis-Admin group has volans, which have read and write permissions on the gitosis-Admin warehouse; the team has three members: volans, Kevin, and Cindy, the reorganization has read and write permissions on the teamwork warehouse. The team_ro group has a Peng member and the team work warehouse has read-only permissions.

Of course, the modifications to these configuration files are only made locally. You must push them to the remote gitserver to make the changes take effect.
Add new files, submit and push them to the GIT Server:
$ Git add.
$ Git commit-am "add teamwork project and users"
$ Git push origin master

Now the server has been built up, and there is an empty project teamwork on the server. What about next? Of course it is a test. empty warehouse cannot be cloned, so a person with write permission needs to initialize a version. Let me do it.

$ Cd
$ Mkdir teamwork-Ori
$ CD teamwork-Ori
$ Git init
$ Echo "/* Add what you want */"> main. c
$ Git add.
$ Git commit-am "initial version"
$ Git remote add oringin git @ Git-server-IP: Teamwork. Git
$ Git push origin master

So far, teamwork has a version. Other team members only need to clone the teamwork warehouse first, and they can play with it at will.
$ Git clone git @ Git-server-IP: Teamwork. Git

In addition, if you have a ready-made git repository and want to put it on the gitserver for use by the Team (for example, you clone an official kernel repository and want to use it as the basic repository internally), what should you do.
First, you need to get a pure Repository from your work warehouse. For example, your work directory is ~ /Kernel: You want to export the pure repository to your USB flash drive and copy it to gitserver.
$ Git clone -- vare ~ /Kernel/Media/udisk
Then, take the USB flash drive and hand it to the gitserver administrator to copy it to/opt/git/and configure the gitosis configuration file.

-------------

Several Methods for configuring the GIT Server

First of all, we need to make it clear that git is a distributed version control system and does not need a fixed server. For simple configuration, you only need to put the GIT project in the shared folder of the LAN server.

1. gitosis, set the http://blog.agdunn.net on Ubuntu /? P = 277
2. gitolite: Set http://realcnbs.com/2010/12/setup-git-server-gitolite-ubuntu/ on Ubuntu
3. WebDAV: Method of configuration: http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt
4. Git daemon a simple git repository management service software http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html
5. Use third-party services such as Repo. Or. cz, GitHub or gitorious

You are welcome to add other methods.

I use gitolite Configuration Services on Amazon EC2 and use GitHub and gitorious

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.