macOS uses git to pull code, commit and push from gitlab
1. Install git
Open the mac terminal and enter the following command to check whether git has been installed on your mac. If the version number shown in the figure below appears, git has been installed
git --version
2. Configure global user information
git config --global user.name "username" # 设置gitlab的用户名
git config --global user.email "[email protected]" # 设置gitlab的邮箱
3. Generate public key
Enter the following command, and when the interactive information appears, keep pressing the Enter key until the public key is generated. If the public key has been generated before, he will ask you whether to overwrite the original public key, just choose Y.
ssh-keygen -t rsa -C "[email protected]"
Enter the following command to view the public key and obtain the specific content of the public key, which starts with ssh-rsa.
cat ~/.ssh/id_rsa.pub
4. Gitlab binds the public key
Copy the content of the public key above, and paste it into the input box of gitlab avatar —> settings —> ssh key.
5. Pull the code from gitlab
cd <你本地文件夹目录> # 我喜欢直接拉取到桌面,我就是 cd Desktop
git clone <远程仓库目录> # 点击 gitlab 项目右上角 clone,复制 ssh 链接
###### 拉取某一分支下的代码
git clone -b <某个分支名> <远程仓库目录>
6. Submit the code to gitlab
6.1 Individual projects
Copy the new code file to the directory you cloned
git add *
git commit -m"<注释>"
git push origin master
git remote add origin # 你刚才建立的项目连接
git push -u origin master
Then go to gitlab to refresh and look at the project, a new code file appears, that is, the code is successfully submitted
6.2 Team project (upload to the specified branch of the specified project)
6. 2. 1 Create a new folder
Put the content you want to upload into the folder
6.2.2 Git initialization
git init
6. 2. 3 Replace branch
At this time, the default branch is the master branch
git checkout -b wyc_dev
Here take wyc_dev as an example, you need to replace it with your own branch name.
6. 2. 4 Specify the warehouse path to be uploaded
git remote add origin https://xxxxx
# 或者
git remote add origin git@xxxxx
Specify your project address, such as: https://… or git@…
6. 2. 5 Select items
git add .
By default, all files under your path are added to the temporary storage area, or you can specify files according to your needs.
6. 2. 6 Add comments for uploaded files
git commit -m '你的备注信息'
Submit the staging area to the local warehouse, which can be some remarks.
6. 2. 7 pull project
- Submitted for the first time and there is content under the current folder
git pull origin wyc_dev --allow-unrelated-histories
The editing interface appears directly: wq
- Not the first submission or there is no content under the current folder
git pull origin wyc_dev
6. 2. 8 push project
git push -u origin wyc_dev
After the submission is complete, check the project in the warehouse.
6.2.9 Inspection
Items in the original warehouse:
Refresh:
This is successfully uploaded to the specified branch of the specified project