Reprinted from: http://blog.csdn.net/w13770269691/article/details/38705473/
Use of Gitlab
Recently, gitlab has been successfully deployed in the company. Since the students have not yet used it, I will write a blog here to explain. If you want to install gitlab, you need some basic knowledge of linux. I recorded the reference of my installation here " http://www.cnbluebox.com/?p=378 "
1. What is git
In view of the fact that some students have not used git yet, let's introduce git first. git is a version control tool. When it comes to version control, you may think of svn. But there is an essential difference between the two.
svn is a centralized version control system. There is only a single centrally managed server that saves revisions of all files, and people working together connect to this server through clients to retrieve the latest files or submit updates.
Git is a distributed version control system. Each terminal is a warehouse. The client does not only extract the latest version of the file snapshot, but completely mirrors the original code warehouse. Each extraction operation is actually a complete backup of the code repository.
Centralized version control:
Distributed version control:
2. GitLab creates a project
Click the "+" on the navigation bar to enter the create project page
This is very simple, mainly about two places:
2.1 namespace
This selection is used to decide which project belongs to, you can choose User as yourself. Or select a group, which will affect the url of the subsequent project. For example, if I select the group suning to create the project SuningTest, then the project will be visible in this group, and the access path is https://domain.com/suning/suningtest
2.2 Visibility Level
There are three levels of authority:
- Private Private, only you or members of the group can access
- Internal All logged in users
- Public, accessible to everyone
3. Use of Git
3.1 Add sshkey
The code transfer protocol between git repositories mainly uses the ssh protocol. Generally, the git user used when building gitlab does not have a password, so you cannot log in directly through ssh. You need to use ssh-keygen to upload the public key and use asymmetric encryption for transmission. Here's how to upload your ssh public key:
3.1.1 Generate sshkey
Type the following command in the terminal, the first step will generate a pair of private key and public key, which exist in ~/.ssh/id_rsa
and ~/.ssh/id_rsa.pub
in respectively. The second step is to view the public key string.
ssh-keygen -t rsa -C "$your_email"
cat ~/.ssh/id_rsa.pub
3.1.2 Save sshkey to gitlab
Click Profile Settings –> SSH Keys –> Add SSH Keys on the panel. Then id_rsa.pub
copy and paste the content in the previous step into the input box and save.
After completing the above two steps, the sshkey is successfully added, and then the code can be uploaded.
3.2 Initial upload code
If you already use git, this step can be skipped for you. Overall it's relatively simple. The following $project_root
represents the project root directory
- Enter the project directory
cd $project_root
- Initialize the git repository
git init
- Add files to repository
git add .
- Submit the code to the repository
git commit -m 'init commit'
- link to git server
git remote add origin [email protected]:namespace/projectname.git
- push code to server
git push origin master
3.3 Clone the code to the local
In svn, we call it checkout. Checkout the code locally. In git, we call it clone, and clone will pull the entire repository locally.
For example, I want to clone the project just now to the local.
git clone [email protected]:namespace/projectname.git
3.4 Set gitignore
There are some files or folders that we don't want to be version controlled, for example .DS_Store build\ xcuserdata thumbs.db
, git provides an ignore scheme.
Create a .gitignore file in the project root directory, and then write the file or folder name to be ignored. This way you can ignore these files under version control.
svn also provides such an ignore scheme, and svn can also set global ignore. This configuration of svn is placed ~/.subversion/config
in the value of global-ignores.
By setting ignore, we can achieve dual management of git and svn, that is, ignore the .git folder in svn, and ignore the .svn folder in gitignore. Interested students can try
3.5 Status of git files
There are 3 states of files under git management, as shown below:
3.6 git basics
Git is broad and profound, and I personally feel that it is much more powerful than svn in terms of its powerful functions and its implementation plan. Post a learning link here, this series is very comprehensive and detailed:
3.7 Graphical git management tool
If you don't like the way of using the command line, you can also use the graphical interface tool SoureTree: http://www.sourcetreeapp.com/ The interface is simple, easy to use, and powerful.
Paste a preview: