Shortly after I joined the new company, all accounts of the company were required to use their own name information due to the company’s name culture. The GitLab warehouse management code used by the company requires each coder to register their own GitLab account using the company’s email address. Yesterday, I was knocked on the small window by the group leader. Your commit information is zhifei, not Seven (alias, my name is not good to listen to), so I foolishly changed the profile information in GitLab, and developed the push code in this way. One week later, I was knocked on the small window again… That’s right, I’m still on Github…

Git config -g user.name ****, git config -g user.email ****@**.com and then generate an SSH key. Set it up on Github, and it’s been silly for years.

Problem: Github, Gitlab information silly confused

The company project uses the GitLab account, while individuals also have personal warehouse code on Github. The company account is the flower name, the company email address, and the Github account is the personal email address. Git commit information, if you do not have a special Settings, will directly use the global username useremail.

Solution:
  1. First, the global Github information does not need to change, directly ignored.
  2. Run the following command in the project directory:
git config --local user.name 'seven' && git config --local user.email '[email protected]'
Copy the code

Go to the root directory of your project and you will find your configuration information at the end of the config file in the.git directory.

[user]
	name = seven
	email = seven@***.com
Copy the code

In fact, if you test this, you will see that now the push code and commit information is the latest name, email. SSH connection to speed up your push and pull. Recently push code, every time you enter username, password. The SSH key is not set.

By default, the SSH key is stored in ~/. SSH/and contains two files id_rsa and id_rsa.pub. If your Github has been set up before, these two files must exist.

To set the SSH key of GitLab, first generate the above two files, but it is a fresh start for GitLab.

ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C "[email protected]"

Copy the code

Note: when you run this command above, you will be asked for your password, so make sure you enter it directly, or set it to empty, otherwise you will be asked to enter your password for id_rsa.gitlab every time you pull or push.

So how do you let your system know which key file to choose? Just a config file. On the command line, run the touch ~/.ssh/config file. Then, edit the content,

Host gitlab.***.com
IdentityFile ~/.ssh/id_rsa.gitlab
User seven
Copy the code

Once configured, you’re done.

Postscript: Today, when I consulted my colleagues about this problem, I unexpectedly found that everyone considered it a trivial matter and automatically ignored this problem, such as commit information flower name and Github account name. Well, I’ve compiled this document just to show you…