Foreword
We can publish some public repositories of open source code on GitHub, but for private repositories we need to charge. The company usually builds its own Git server, and I also practice by building it on my own server.
Before we start, let's talk about the server information. Here is Alibaba Cloud's CentOS 6.5 64-bit operating system.
One confirm whether the server is installed with Git
[ root@iZ25r8k6ifuZ git]# rpm -qa git
git-1.7.1-3.el6_4.1.x86_64
It has also been installed here, if it is not installed, you can use yum install git to install it.
Two create a git user
Here you can choose to create a new user to test, or you can directly use your root to perform the following operations. The author also looked at the information step by step, here is to create a new user teslachen to operate.
[ root@iZ25r8k6ifuZ ~]# useradd tesla
[ root@iZ25r8k6ifuZ ~]# passwd tesla
Change the password of user Tesla.
New password:
Invalid password: it does not contain enough different characters
Invalid password: too simple
Re-enter the new password:
passwd: All authentication tokens have been successfully updated.
Note 1: Please add sudo if you have insufficient permissions to create a user;
Note 2: If the user password is too simple, there will be a prompt, but it can still be set successfully.
Three generate ssh public key
Many Git servers use SSH public keys for authentication. In order to provide the SSH public key to the Git server, if a system user does not already have the key, a copy of it must be generated in advance.
Linux can run ssh-keygen -t rsa on this machine to generate a key and copy the .pub file to the server.
[ root@iZ25r8k6ifuZ ~]# su tesla
[ tesla@iZ25r8k6ifuZ root]$ cd ~[tesla@iZ25r8k6ifuZ ~]$ mkdir .ssh
[ tesla@iZ25r8k6ifuZ ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key(/home/tesla/.ssh/id_rsa):
Enter passphrase(empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/home/tesla/.ssh/id_rsa.
Your public key has been saved in/home/tesla/.ssh/id_rsa.pub.
The key fingerprint is:13:bf:75:ba:67:7f:0e:a0:47:7a:fe:25:bc:81:85:c3 tesla@iZ25r8k6ifuZ
The key's randomart image is:+--[ RSA 2048]----+|||||.|| o ..|| S . E o ||. O ||+==.||+.o.|| o+oo+|+-----------------+[tesla@iZ25r8k6ifuZ ~]$ cd .ssh/[tesla@iZ25r8k6ifuZ .ssh]$ cat id_rsa.pub >>~/.ssh/authorized_keys
exit
Four add tesla to the sudoers file
The tesla user does not have operating permissions on some folders, so he can modify the /etc/sudoers file to change his permissions. The top administrator user opens with the following command.
[ root@iZ25r8k6ifuZ ~]# visudo
Then we find the following line in vim
root ALL=(ALL) ALL
Press the i key to start inserting, press Enter to add in the following line
tesla ALL=(ALL) ALL
Then press the esc key, enter: wq, press Enter to save and exit
Five create a Git code warehouse
[ root@iZ25r8k6ifuZ ~]# mkdir /teslaRepo
[ root@iZ25r8k6ifuZ ~]# cd /teslaRepo/[root@iZ25r8k6ifuZ teslaRepo]# sudo mkdir teslaProject.git
[ root@iZ25r8k6ifuZ teslaRepo]# chown tesla:tesla /teslaRepo/[root@iZ25r8k6ifuZ teslaRepo]# chown -R tesla:git /teslaRepo/[root@iZ25r8k6ifuZ teslaRepo]# cd teslaProject.git/[root@iZ25r8k6ifuZ teslaProject.git]# sudo git --bare init
Initialized empty Git repository in/teslaRepo/teslaProject.git/
Such a Git repository called teslaProject is created
Six local test use
You can perform local testing directly on the server, or directly use your computer to test. Below I use my own MBP to test.
localhost:~ okay$ cd Desktop/git/
localhost:git okay$ mkdir teslaRepo
localhost:git okay$ cd teslaRepo/
localhost:teslaRepo okay$ git init
Initialized empty Git repository in/Users/okay/Desktop/git/teslaRepo/.git/
localhost:teslaRepo okay$ git remote add origin [email protected]:/teslaRepo/teslaProject.git
The above command creates a folder locally and adds a remote warehouse on the server
localhost:teslaRepo okay$ touch a.txt
localhost:teslaRepo okay$ git add a.txt
localhost:teslaRepo okay$ git commit -m "init commit"[master(root-commit) d14cd3b] init commit
1 file changed,0insertions(+),0deletions(-)
create mode 100644 a.txt
The above command created a.txt locally and submitted it once locally
localhost:teslaRepo okay$ git push origin master
[email protected]'s password:
Counting objects:3, done.
Writing objects:100%(3/3),202 bytes |0 bytes/s, done.
Total 3(delta 0), reused 0(delta 0)
To [email protected]:/teslaRepo/teslaProject.git
*[ newbranch] master -> master
The above command pushes the local code to the remote server, let's clone it locally to see if it is correct
Seven local clone
localhost:git okay$ mkdir ttt
localhost:git okay$ cd ttt
localhost:ttt okay$ git clone [email protected]:/teslaRepo/teslaProject.git
Cloning into 'teslaProject'...
[email protected]'s password:
remote: Counting objects:3, done.
remote: Total 3(delta 0), reused 0(delta 0)
Receiving objects:100%(3/3), done.
Checking connectivity... done.
clone is complete, let us look at the folder directory
The a.txt file previously pushed to the server has been cloned
----Dividing line-----
cut -d:-f1 /etc/group
cut -d:-f1 /etc/passwd
git clone git@your_gitServer_ip:/home/gitrepo/sample.git
//Demonstrate with master branch
git checkout master
git remote rm origin
git remote add origin git@your_gitServer_ip:/home/gitrepo/sample.git
git push -u origin master
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts