Reprint: Build the base git repository

Source: Internet
Author: User
Tags version control system

GitHub is a remote repository that hosts open source code for free. But for some source code such as the life of the business company, neither want to open source code, but also reluctant to pay for the protection of GitHub, then you can only build a git server as a private warehouse use.

Building a git server requires a machine running Linux and is highly recommended for Ubuntu or Debian, so you can install it with a few simple apt commands.

Assuming you already have sudo permissions for the user account, below, formally start the installation.

The first step is to install Git:


$ sudo apt-get install git

The second step is to create a git user to run the GIT service:


$ sudo adduser git

The third step is to create a certificate login:
Collect all the public keys of the users who need to log in, their own id_rsa.pub files, and import all the public keys into the/home/git/.ssh/authorized_keys file, one at a-line.

The fourth step is to initialize the GIT repository:
First select a directory as the Git repository, assuming/srv/sample.git, enter the command in the/SRV directory:


$ sudo git init --bare sample.git

Git creates a bare repository with no workspaces, because the GIT repository on the server is purely for sharing, so you don't let users log on to the server directly to the workspace, and the Git repositories on the server usually end up with. Git. Then, change owner to Git:git

$ sudo chown -R git:git sample.git

Fifth step, disable the shell login:
For security reasons, the GIT user created in the second step is not allowed to log in to the shell, which can be done by editing the/etc/passwd file. Find a line similar to the following:


git:x:1001:1001:,,,:/home/git:/bin/bash

Switch

git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

In this way, git users can use git normally via SSH, but cannot log in to the shell because the Git-shell we specify for git users automatically exits every time a login is logged in.

Sixth step, clone the remote repository:
Now, you can clone the remote repository with the git clone command and run it on your own computer:


$ git clone [email protected]:/srv/sample.gitCloning into ‘sample‘...warning: You appear to have cloned an empty repository.

The rest of the push is simple.

Managing Public keys
If the team is small, it is possible to collect everyone's public key and put it in the server's/home/git/.ssh/authorized_keys file. If the team has hundreds of people, it is not possible to play this way, then you can use gitosis to manage the public key.
Here we do not introduce how to play gitosis, hundreds of people's team are basically in the 500 strong, I believe that a high level of Linux administrator problem is not big.

Manage permissions
There are many companies that not only depend on the source code such as life, but also depending on the employees as thieves, will be in the version control system set up a set of comprehensive permissions control, each person has read and write access to each branch or even under each directory. Because Git was developed for Linux source code hosting, Git also inherits the spirit of the open source community and does not support permission control. However, because git supports hooks, it is possible to write a series of scripts on the server side to control the commit and so on, to achieve the purpose of permission control. Gitolite is the tool.

Reprint: Build the base git repository

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.