Linux build git remote server steps detailed

Source: Internet
Author: User
Tags ssh git clone


Building a git server requires a machine running Linux that is strongly recommended for use with CentOS:

Create a git user to run the GIT service:

Useradd git

Su-git//Switch to git under this user
The public key for all users who need to log on is to collect their own id_rsa.pub files, import all the public keys into the/home/git/.ssh/authorized_keys file, one line.

You can run this command and then generate an. SSH directory and a file such as Id_rsa and id_rsa.pub in your home directory.

Ssh-keygen-t rsa-c "Youremail@example.com"

Initial a git repository

First select a directory as a git repository, assuming it is/data/git/test.git, and enter the command in the/data/git directory:

Cd/data/git//Switch to a directory
Git init--bare sample.git//Create a naked library named Sample.git

If it's a new project, if you want to put it in the/data/web directory,

Cd/data/web
git clone git@ host address (IP address/domain name):/data/git/sample.git
# This will create a catalog of sample.

If an existing project needs to be pushed into Git managed directories such as/data/web/

Cd/data/web/sample
Git init
Git remote Add origin git@localhost:/data/git/sample.git//Add a long distance warehouse path


(General input Yes on the line, do not need to modify the file, I have been this hole, you must enter Yes OH)

And then again, the simple git operation.

git Add.
git commit-m ' submit information ';
Git push Origin master; Push to remote
Git pull Origin master; Pull down from the remote


When the push, the remote automatic pull

Cd/data/git/sample.git
CD hooks
CP Post-update.sample Post-update

Vim Post-update

Modified to read as follows:

#!/bin/sh
# Switch to the desired directory
Cd/data/web/sample
Unset Git_dir
Git pull Origin Master
At this point an environment is OK, pay attention to the issue of permissions. Bye

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.