How to configure a Git account (not yet)

Add a public Key to git server (Github or Gitlab, etc.)

Set the Git user name and mailbox

git config --global user.name "Username"
git config --global user.email "Email"
Copy the code

Note that the –global parameter of the git config command indicates that all git repositories on your machine will use this configuration, as well as different user names and Email addresses for each repository.

Generate the SSH Key

ssh-keygen -t rsa -C "Email"
Copy the code

In the SSH directory, two files id_rsa and id_rsa.pub are generated.

  • Id_rsa (private key)
  • Id_rsa. Pub (Public key)

Add a public key to a Git server

Add the contents of id_rsa.pub to SSH keys

How to configure multiple Git accounts

The company’s code hosting tool is also Git and then has its own GitLab server, if the above configuration is used

git config --global user.name "Username"
git config --global user.email "Email"
Copy the code

It is very important that your own git and your company’s git cannot exist at the same time

Suppose account A is set for the first time and account B is set for the second time.


Basic process: Generate a new SSH Key-> configure the config file -> add a public Key to another Git server

Generate a new SSH Key

ssh-keygen -t rsa -C Mailboxes "B"
Copy the code

Note: The default file cannot be generated by pressing the return button this time, because the file name will be overwritten, assuming the generated file name

  • B_id_rsa (private key)
  • B_id_rsa. Pub (Public key)

Configuring the Config file

For Windows, create a TXT file and change the suffix to config

Configuration is as follows

# gitlabHost git.A.com HostName git.A.com // Enter the git url PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa // First private key name (private key name of account A) User XXX // User name# githubHost git.B.com HostName git.B.com // Enter the git url PreferredAuthentications publickey IdentityFile ~/.ssh/B_id_rsa // Private key name of account B User XXX // User nameCopy the code

Git Configuration

Configure a Host for each account and an alias for each Host. Configure the HostName and IdentityFile properties for each Host

The Host name can be whatever you like, but this will affect git-related commands, such as: Host mygithub such definition, the command is that git @ followed behind name to mygithub git clone git @ mygithub: PopFisher/AndroidRotateAnim git

HostName               // This is the real domain address IdentityFile               / / here is the address of id_rsa PreferredAuthentications / / configure login with what authority certification, can be set to publickey, password, publickey, such as the rid_device_info_keyboard -interactive User                       // Configure the user nameCopy the code

The resources

  • https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
  • http://www.jianshu.com/p/f7f4142a1556
  • https://my.oschina.net/csensix/blog/184434
  • https://www.cnblogs.com/popfisher/p/5731232.html