Build a Git server Repository

Source: Internet
Author: User

Build a Git server Repository

Git can be used to easily build a Git server repository. The principle is to log on via ssh. The advantage of this method is that it is simple.

Procedure:

#1. Install git:

sudo apt-get install git
2. Create a git user to run the git service:
sudo adduser git
3. Create a certificate to log on:

Collect the public keys of all users that need to log on, that is, their own id_rsa.pub file, and import all the public keys/home/git/.ssh/authorized_keysFile, one line.

4. initialize the Git Repository:

Select a directory as the Git repository. Assume that/home/my_name/repositorys/git-template.git, In/home/my_name/repositorysEnter the following command in the directory:

sudo git init --bare git-template.git

Git creates a bare repository without a work zone. Because the Git repository on the server is purely for sharing, users are not allowed to directly log on to the server to change the work zone, and the Git repository on the server usually uses. git end. Then, change the owner to git:

sudo chown -R git:git git-template.git
5. Disable shell Logon:

For security reasons, the git user created in step 2 is not allowed to log on to the shell, which can be completed by editing the/etc/passwd file. Find a line similar to the following:

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

Changed:

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

In this way, git users can normally use git through ssh, but cannot log on to the shell, because the git-shell that we specify for git users will automatically exit upon every login.

6. clone a remote Repository:

Now, you can clone the remote repository using the git clone command and run the following command on your computer:

Git clone git@XXX.XXX.XXX.XXX:/home/my_name/repositorys/git-template.git (XXX. XXX is the IP address of the server)
7. Public Key Management

If the team is small, it is feasible to collect everyone's public keys and put them in the/home/git/. ssh/authorized_keys file on the server. If the team has hundreds of people, they won't be able to do that. In this case, you can use Gitosis to manage the public key.

8. Example:
  • Clone project:git clone git@192.168.6.80:/home/my_name/repositorys/git-template.git
  • Submit changes:git push, Or specify branchs:git push origin master
  • Update Data:git pull
Note:

1. the "git init-bare" method is used to create a so-called bare repository, which is called a bare repository because it only stores version information submitted by git history, users are not allowed to perform various git operations on the above. If you have to perform the operations, you will only get the following error ("This operation must be run in a work tree ") this is why it is best to initialize the remote warehouse as a bare warehouse.

Git Tutorials:

GitHub tutorials

Git tag management details

Git branch management

Git remote repository details

Git local Repository (Repository) Details

Git server setup and Client installation

Git Overview

Share practical GitHub tutorials

How to Build and use Git servers in Ubuntu

Git details: click here
Git: click here

This article permanently updates the link address:

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.