As we all know, the version system is essential in the development environment, but we can host the code on GitHub for free. If we do not intend to disclose the source code of the project and the company does not want to pay for it, then we can build a Git by ourselves. The server can use Gitosis to manage the public key, which is more convenient. |
Build environment:
Server CentOS 6.6 + git (version 1.8.3.1)
Client Windows10 + git (version 2.11.1.windows.1)
1. Install Git related software
Linux is the server system, Windows is the client system, and Git is installed separately
Install the server:
[root@linuxprobe ~]# yum install -y git [root@localhost ~]# git --version //After installation, check the Git version git version 1.8.3.1
Install the client:
Download Git for Windows , address: Git for Windows
Once installed, you can use Git Bash as a command -line client.
$ git --version git version 2.11.1.windows.1 //After installation, check the Git version
Install Gitosis
[root@linuxprobe ~]# cd software/ [root@linuxprobe software]# git clone https://github.com/res0nat0r/gitosis.git [root@linuxprobe software]# yum install python-setuptools -y [root@linuxprobe software]# cd gitosis [root@linuxprobe gitosis]# sudo python setup.py install
The following message appears to indicate that the installation was successful
Using /usr/lib/python2.6/site-packages Finished processing dependencies for gitosis==0.2
2. Create a git user on the server side to manage the Git service
[root@linuxprobe ~]# id git //Check if the git user exists id: git: no such user [root@linuxprobe ~]# useradd git [root@linuxprobe ~]# echo "123" | passwd --stdin git [ root@linuxprobe ~]# su - git //Switch to git user
3. Configure the public key
Configure the manager on Windows, the git server needs some managers, upload the public key of the developer machine to the server, add it as the manager of the git server, and open the git command line
$ ssh-keygen -t rsa //Enter all the time, no need to set a password ~ scp ~/.ssh/id_rsa.pub [email protected]:~ //Copy to the git server
4. Configure gitosis
Use the git user and initialize gitosis
[root@linuxprobe ~]# cd .ssh [root@linuxprobe ~]# gitosis-init < ./id_rsa.pub Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/ [root@linuxprobe ~]# chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update //添加权限
Clone gitosis-admin to the manager host on the Windows machine
$ git clone ssh://[email protected]:22/gitosis-admin.git $ cd gitosis-admin $ ls $ gitosis.conf keydir
gitosis.conf: git server configuration file
keydir: store the client public key
Configure the gitosis.conf file
$ vim gitosis.conf [gitosis] [group gitosis-admin] #Group name members = yueyong@SHA2-001 #Group member writable = gitosis-admin #Project name [group test] //The "test" project group is added here, Upload to a git server members = yueyong@SHA2-001 writable = test
Create a local test warehouse on the Windows manager machine and upload it to the git server
$ git config --global user.name "Your Name" //The first submission needs to set personal information, user name and email $ git config --global user.email "[email protected]" $ cd ~/repo $ mkdir test $ git init $ tocuh readme.txt
submit to remote server
$ git add . $ git commit -a -m 'init test' $ git remote add repo [email protected]:test.git //The name of the repo remote library, which can be replaced with any name $ git push repo master //Upload All local branch codes to remote corresponding branches
The server will automatically create a test warehouse
[git@repositories]# pwd /home/git/repositories [git@linuxprobe repositories]$ ls gitosis-admin.git test.git
5. Add other git user developers
Due to the increasing number of the company's development team, it is troublesome to manually add the developer's private key to /home/git/.ssh/authorized_keys. The administrator of the above Windows machine collects the private key id_rsa.pub file of other developers, and then uploads the On the server, after the configuration is completed, the user can obtain project permissions, and can pull and push projects from remote warehouses to achieve joint development projects.
$ cd ~/gitosis-admin/keydir $ mv ~/id_rsa.pub [email protected] //Modify the public key to hostname.pub $ vim gitosis.conf [group test] writable = test members = yueyong@SHA2 -001 zhangsan@SHA2-002 //add member
$ git add . $ git commit -m "add zhangsan@SHA2-002 pub and update gitosis.conf" $ git push repo master
After the push is completed, the newly added developers can develop the project, and subsequent personnel can be added in this way, and the developers can directly clone the warehouse.
git clone [email protected]:/home/git/repositories/test.git reported an error problem: ERROR: gitosis serve main repository read access denied According to this error report, it can be seen that the key is no problem, through investigation, it is found that it should not be This /home/git/repositories/test.git is written in full, git clone [email protected]:test.git This is all right.