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