Use SSH to manage git servers

Source: Internet
Author: User


GitosisIt is a little complicated to manage git servers. Generally, it is not necessary to use small-scale development. It can be managed simply by using Linux ssh. The procedure is as follows:

1. Add a user and prepare the public key and private key.

Add the user git, And the password is also git

Adduser Danny
Passwd Danny
Adduser git
Passwd git

The Public Key generated by root is under/root/. Ssh/id_rsa.

Ssh-keygen-T RSA

Then run su Danny/su git separately.

Ssh-keygen-T RSA

Return to root and execute

CP/home/Danny/. Ssh/id_rsa.pub/home/git/. Ssh/danny_rsa.pub

CD/home/git/. Ssh/

Cat danny_rsa.pub> authorized_keys

Cat authorized_keys

Rm-RF danny_rsa.pub

Chown git authorized_keys

Mkdir/home/git/Repos

Chown-r git/home/git/Repos

2. Create a test project

Switch to the GIT user, go to the git home directory, and create the testproject

Su git

Cd ~

Mkdir/home/git/repos/testproject

CD/home/git/repos/testproject

Initialize git Library
Git init

Set User
Git config user. Email "git@ujs.edu.cn"
Git config user. Name "Git"

Create a test file in the directory and submit it.
VI TEST

Git add Test

Git add -- all add all files to be added

Git commit-a-m "add Test by git"

In this case, the foundation is established.CodeLibrary.

Create a branch. The default value is the master branch. Note: The current branch of the server cannot be submitted by other users.

Git branch develop
View Branch
Git Branch
Switch Branch
Git checkout develop

Here we only allow other users to submit the changes to the develop branch, and then the administrator maintains the master branch, so we switch back to the master branch.

Git checkout master

3. Clone test project

Switch to the Danny user and enter the main directory of Danny.

Su Danny

Cd ~

Git clone git @ localhost:/home/git/repos/testproject

Note: Clone only downloads the files in the current directory. No matter whether you are in the master or develop branch, only the files in the current directory are downloaded. In this example, because git switches back to the master branch, the content of the master branch is cloned here.

CD testproject

Set User
Git config user. Email "danny_xcz@163.com"
Git config user. Name "Danny"

Create a test file in the directory and submit it. Note that only the library in the Danny directory is submitted, and the library in the GIT user directory is not submitted.
VI Test2

Git add Test2

Git commit-a-m "add Test2 by Danny"

At this point, you can submit the changes to the server. Because git users are on the master branch, they cannot submit the changes to the master branch, but can only submit the changes to the develop branch.

Refusing to update checked out branch: refs/heads/Master

Git push origin master: Develop submit the local master branch to the remote develop Branch

If the GIT user wants to see Test2, he must switch to the master branch.

4. Use tortoisegit for connection in Windows

Generate the public key and private key through the bash command of mysygit on the Administrator Windows machine; in the C: \ Documents ents and Settings \ Administrator \. Ssh directory

Ssh-keygen-T RSA

Use D: \ Program Files \ tortoisegit \ bin \ puttygen.exe and save it as a dedicated putty format.

"Load" id_rsa under the Administrator \. Ssh directory

"Save private kay" putty. PPK

Copy the line in the public key to git/. Ssh/authorized_keys.

Use tortoisegit to clone a project

SSH: /// git@172.20.1.7/home/git/repos/testproject

Load putty key "C: \ Documents ents and Settings \ Administrator \. Ssh \ putty. PPK"

Note that the remote master and develop branches are inconsistent. The develop branch has one more Test2 file. Because the GIT user is under the master, only the test file is cloned. Must be the latest develop branch of pull.

Git pull origin develop

Add the test3 file locally and submit it to the developer branch of the GIT user.

Git push origin master: Develop

Note: if you cannot push data to the current master branch on the server, an error is returned.

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.