Use SSH to pull code from the GitLab repository
Background#
On the company's Mac computer, it is necessary to migrate the code from the Gitee repository to the company's GitLab code repository, and I prefer to associate the Git repository using SSH. I also like to use the simple and straightforward method below to configure Git. Previously, I played with Git mostly on Windows 10, experimenting with various operations, such as: creating branches, switching branches, merging branch code, viewing the history of a single file, comparing the current file with the previous version, and understanding the purpose of each branch.
Additionally, I have used IDEA and Android to submit code, and their submission methods are quite similar. I have also used SVN to submit code, but I find it less elegant. I usually use two methods to submit code: one is command-line based, and the other is visual, just clicking around. A more advanced method is Sourcetree.
Execution Steps#
1. Configuration#
The following commands are executed in the terminal under the /Users/user/.ssh directory:
1.1 Manual configuration
config file
In the .ssh/ directory, if there is no config file, you need to create one.
Create command: touch config
# gitlab
Host gitlab.com
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa_gitlab
User usertest
.gitconfig file
In the user directory, find according to the actual situation.
[user]
name = usertest
email = [email protected]
[core]
autocrlf = input
When collaborating between Windows and Mac, there is a problem:
It prompts to modify git core.autocrlf,
This is due to differences in editors or Windows programmers adding carriage return and line feed characters to files in cross-platform projects. Some subtle whitespace changes may inadvertently enter everyone's collaborative work or submitted patches.Reference: https://blog.csdn.net/u012364372/article/details/123215289
Set autocrlf = input on Mac, and set autocrlf = true (default value) on Windows.
1.2 Command method:
git config --global user.name "your_name"
git config --global user.email "[email protected]"
2. Generate Key#
Generate key:
ssh-keygen -t rsa -C "[email protected]"
For specific Git configuration of SSH keys, please refer to: multiple git account configuration
3. Verify Success#
The address of the self-built GitLab repository may differ; change it according to the actual situation.
4. Configure SSH Key in GitLab Remote Repository#
Reference: Mac configure Git and common commands_mac git configuration
The location of SSH keys configuration may vary slightly between different versions of GitLab; find it in the settings yourself.
Attachments#
Reference: https://blog.csdn.net/nxg0916/article/details/135911954
multiple git account configuration
git submit code to local branch
To reiterate:
The key steps for submitting code are:
git status
git pull
git status
git add .
git commit -m "description"
git push
Note: Before submitting code, pull the code first, then submit the code.