Remote warehouse refers to the project warehouse hosted on the network. Now there are many project hosting platforms on the Internet, such as code cloud, Github, GitLab and so on. Of course, if you don’t want your code to be open source, you’ll have to pay for a separate space, or build your own project repository on your own server.

The connection modes between local Git and remote server GitLab are mainly divided into SSH and HTTP.

HTTP mode: In this mode, only “Public” can be selected when a project is created. HTTP mode cannot be used for connection in Private and Internal Private modes. Security Settings must be carried out in consideration of security. SSH mode: This is a relatively secure mode. The transfer between the local Git repository and the remote GitLab repository is encrypted by SSH. SSH mode can be used in all three project modes.

In this article I use the gitLab remote repository as an example. Since the transfer between the local Git repository and the GitLab repository is encrypted by SSH, you must have the GitLab repository authenticate your SSH key. Before doing so, you must generate an SSH key.

What is a public key? 1. Many servers require authentication, and SSH authentication is one of them. Generate a public key on the client and add the generated public key to the server so that you don’t have to enter a username and password every time you connect to the server. 2. Most Git servers use SSH authentication. You need to send the generated public key to the code repository administrator and ask him to add it to the server.

1. Configure the local Git

  • Local git download, directly go to the official website to download and install.
  • What the username and mailbox do: The username and mailbox address are variables on the local Git client. Each time a user submits code, the user name and email address are recorded
  • To configure a global user name and email address, run the following commands:
git config --global user.name "yourname"

git config --global user.email youemail 
Copy the code
  • To view the global user name and mailbox, run the following commands:
git config --global user.name

git config --global user.email
Copy the code
  • To view the user name and email that have been set:
git config --list
Copy the code
  • After the configuration is complete, the global user name and mailbox will be written to the. Gitconfig directory of the user in drive C, for example:



    You can also change the user name or mailbox directly by opening it in the editor.

If you want to change your git user name and mailbox, you can change your git user name and mailbox.

2. Run commands to change the git user name and the email address to be submitted

  • If you want to modify the current global user name and email address, you need to add a parameter in the preceding two commands: – global, representing the global. Note: Set the mailbox (without double quotes).
git config  --global user.name  "yourname"
git config  --global user.email youremail
Copy the code
  • (2) Modify the current project, and the commands are:
git config user.name "yourname"
git config user.email youremail
Copy the code

After the configuration is complete, the username and mailbox of the single repository will be written to the config file of the repository. Git.

Modify git configuration files directly

  • (1) Open the global. Gitconfig file:
vim ~/.gitconfig 
Copy the code
  • Open the file below and modify it directly in the file

  • (2) Open the config file in the current project, which is in the.git directory of each project, and directly enter the directory for editing. Of course, if not modified, the default opening does not have the corresponding user name and password. The corresponding field will be generated in config only after modification.

3. After configuring the local Git, generate the SSH key and configure the GitLab SSH public key.

  • Create a new folder to clone the project, check whether the host has SSH Key, enter:
cd ~/.ssh
ssh-keygen -t rsa -C "[email protected]"
ll
Copy the code

To execute the key generation command, you can basically press Enter all the way. However, note that there will be a prompt during the command execution. Enter the password of the key (at the red arrow in the figure below, enter the same password twice, that is, confirm the password again), do not need to enter the password directly.

Generating public/private RSA key pair. # Generating public/private key pair

Enter file in which to save the key (/c/Users/ XDR /.ssh/id_rsa):

Enter passphrase (empty for no passphrase): # If you do not want to set the password and do not Enter the content, press Enter.

I’ve already generated it here:

  • If the. SSH directory does not exist, run the generate public key command to create it manually
mkdir ~/.ssh
Copy the code
  • Go to this folder and run the command to generate an SSH key. Then press Enter three times. In the.ssh folder, you get id_rsa and id_rsa.pub. Among themid_rsaIs thatThe private key.id_rsa.pubIs thatThe public keyThese files can be found in C:\Users\ users.ssh.

  • Open the id_rsa.pub file and copy the contents
Pub or vim id_rsa.pub or cat ~/.ssh/id_rsa.pubCopy the code
  • Log in to GitLab account, click profile picture, Setting->SSH Keys, paste the copied public Key into the Key text box, and add the title casually.
  • Now that the Git/GitLab connection is configured, you can move on to your project on ClonegitLab.
  • Git public key link gitlab or Gitlab form is almost similar.
  • Also check out another article I wrote about public keys, SSH key creation and key login Settings for Linux servers