2.2: project codes Clone and Push
Suppose yqc user is a developer, and now he wants to write code for test-app1 under test software.
The client PC address used is node111 (192.168.1.111).
2.2.1: Clone project
2.2.1.1: Clone with HTTP
2.2.1.1.1: copy the HTTP clone link of the item
Log in to gitlab with yqc user, enter the test software / test-app1 project page, and copy the HTTP clone connection.
2.2.1.1.2: client git clone
Execute the clone command on the client host:
Create a separate working directory for code cloning and uploading.
root@node111:~# mkdir /workspace root@node111:~# cd /workspace/ root@node111:/workspace# git clone http://192.168.1.121/test-software/test-app1.git Cloning into 'test-app1'... Username for 'http://192.168.1.121': yqc Password for 'http://yqc@192.168.1.121': warning: You appear to have cloned an empty repository.
You appear to have cloned an empty repository
2.2.1.2: Clone with SSH
SSH cloning requires adding the client's public key to Gitlab in advance. In this way, there is no need to enter user name and password when cloning private and internal projects and uploading code.
2.2.1.2.1: client creates SSH key pair
Generate ssh key pair:
root@node111:~# ssh-keygen
The generated key pair is stored in the current user's home directory ssh / Directory:
Among them,
id_rsa is the private key, which is saved in the local machine and used to verify the public key;
id_rsa.pub is the public key, which is transmitted to the opposite end and provided during encrypted communication to verify identity.
root@node111:~# ll /root/.ssh total 16 drwx------ 2 root root 4096 Apr 23 14:09 ./ drwx------ 11 root root 4096 Apr 23 14:09 ../ -rw------- 1 root root 1679 Apr 23 14:09 id_rsa -rw-r--r-- 1 root root 402 Apr 23 14:09 id_rsa.pub
2.2.1.2.2: add SSH Key for Gitlab users
The public key of the client is added here.
root@node111:~# cat /root/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDASlumUB3sH81YLr+ZpN4SPU/1Q6Y522WZ4UaZX8p7pJbWXpmM3soUW6+0CF3w/EYQumjbWbnkYLVBXgoHGLohGgT+mc13dRc2jI7OGIxym2HdY/RzDefa7IdWZxFmy8B6+kw3VoiOGMb8GS3yC6KiKFwwCZCh5EBg7x4+6NRkyMsWaj1VZqFQpUDU8QUtRW4oAMmitIAC/k2xxBrW9pSomfqy5gi6m1hEk6VrDp2NnuyTpeTwBKShPV79tcZ+ciJztdSXUPpJLohjQB4DojNeaUw5DQZfOwedJ/7z9YxolkPD8M0RNqXV0xucyCDLANeChv+v0YZtukE/WMATpBG3 root@node111.yqc.com
Log in to Gitlab with yqc user and enter user settings:
Click SSH Keys to add the public key.
2.2.1.2.3: copy SSH clone link of project
2.2.1.2.4: client git clone
When using key cloning for the first time, you need to enter yes to confirm, and then you don't need it.
root@node111:/opt# git clone git@192.168.1.121:test-software/test-app1.git Cloning into 'test-app1'... The authenticity of host '192.168.1.121 (192.168.1.121)' can't be established. ECDSA key fingerprint is SHA256:7axVWAVMgqQAAr3voX79pFVkb0zNywL1j+eKpbtJVac. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.121' (ECDSA) to the list of known hosts. warning: You appear to have cloned an empty repository.
2.2.2: Push project
The steps to edit and upload the project code to Gitlab are as follows:
Edit the code -- > git add to the temporary storage area -- > git commit to the local code warehouse -- > git push to the Gitlab warehouse.
The whole process involves several areas:
-
Workspace: the code storage directory under Clone (or the directory where developers write code), which is usually named after Project.
-
Temporary storage area: a place where the modified code is temporarily stored. Use git add command to transfer the modified code from the work area to the temporary storage area.
-
Local warehouse: the local code warehouse also has the function of version control. git commit is used to submit the code in the temporary storage area to the local warehouse.
It can be understood as a git repository for developing individuals.Gitlab is equivalent to a distributed version control system. It also has version control function locally on the client. If there is no network, users can submit the code locally first, and then synchronously upload the locally submitted code to gitlab server when there is a network.
-
Remote warehouse: the code warehouse of Gitlab server.
It can be understood as a git warehouse for multiple development to realize multiple development cooperation.
2.2.2.1: modify project code
Here, only one index page is edited for the project to demonstrate.
Enter the project working directory, edit a page file and save it:
Use v1 to identify the version.
root@node111:~# cd /workspace/test-app1/ root@node111:/workspace/test-app1# vim index.html <h1> testapp-1 page v1 </h1>
2.2.2.2: git add puts the code into the temporary storage area
Put the code files in the current directory into the staging area:
root@node111:/workspace/test-app1# git add .
2.2.2.3: git commit submits the code to the local warehouse
When submitting, you need to use - m to specify the submission information, that is, the version description of this submission.
root@node111:/workspace/test-app1# git commit -m "v1" [master (root-commit) e6531ba] v1 1 file changed, 1 insertion(+) create mode 100644 index.html
2.2.2.4: git push uploads the code to Gitlab server
Enter yqc user and password and upload the code to the corresponding project of Gitlab.
The default submission is to the master branch.
root@node111:/workspace/test-app1# git push Username for 'http://192.168.1.121': yqc Password for 'http://yqc@192.168.1.121': Counting objects: 3, done. Writing objects: 100% (3/3), 233 bytes | 233.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://192.168.1.121/test-software/test-app1.git * [new branch] master -> master