git user manual -- Remote warehouse

1. Create a warehouse on gitlab

2. SSH Key

Because we used gitlab for the first time to create SSH Key before pushing files. In the user's home directory, check to see if there is a. ssh directory. If there is, check to see if there are two files in this directory, i.e. id_rsa and id_rsa.pub. If there are already, you can skip to the next step. If not, open the Shell (Git Bash under Windows), and create the SSH Key:

$ ssh-keygen -t rsa -C "youremail@example.com"

Make youremail@example.com your own email address, then return all the way, using the default value.

$ ssh-keygen -t rsa -C'xingshuqiang@thtf.com.cn'
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/XingSQ/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/XingSQ/.ssh/id_rsa.
Your public key has been saved in /c/Users/XingSQ/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:m6i1wrrLTNcTtQfkmlAfx42bn+321CPiXs2a6KuhMdY xingshuqiang@thtf.com.cn
The key's randomart image is:
+---[RSA 3072]----+
|      . o..o     |
|     . + oo .    |
|    .   =  o     |
|     . + oo      |
|      + S .. o   |
|     . o.+  o + .|
|  ... =+oE . + +o|
| + .oo.o+ o + *..|
|  *+.... .+*.+ ..|
+----[SHA256]-----+

After the creation, you can find the. ssh directory in the user's home directory. There are two files in the directory: id_rsa and id_rsa.pub. These two are the secret key pairs of SSH Key. Id_rsa is the private key and cannot be disclosed. Id_rsa.pub is the public key. You can tell anyone at ease.

Log in Gitlab, open the user settings, SSH key page:

Then, paste the content in id_rsa.pub into the key text box, fill in any Title, and click "add key":

OK, now I can push the existing local warehouse to the remote warehouse. The command is as follows:

cd existing_folder
git remote add origin git@10.10.82.53:xsqself/gittest.git
git push -u origin --all
git push -u origin --tags
$ git push -u origin --all
The authenticity of host '10.10.82.53 (10.10.82.53)' can't be established.
ECDSA key fingerprint is SHA256:GoURASw5jPqCRTZi2HvhnC+e2wVEne7GmOPFxZToEvw.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.82.53' (ECDSA) to the list of known hosts.
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (13/13), 1.24 KiB | 126.00 KiB/s, done.
Total 13 (delta 2), reused 0 (delta 0)
To 10.10.82.53:xsqself/gittest.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
$ git push -u origin --tags
Everything up-to-date

Success. Now you can see the files we pushed on the gitlab page.

Push the contents of the local library to the remote. With the git push command, the current branch master is actually pushed to the remote.

Because the remote library is empty, when we push the master branch for the first time, we add the - u parameter. Git will not only push the contents of the local master branch to a new remote master branch, but also associate the local master branch with the remote master branch. In the future, when we push or pull, we can simplify the command.

SSH warning

When you first use Git's clone or push command to connect to GitHub, you will get a warning:

The authenticity of host 'xx.xx.xx.xx(xx.xx.xx.xx)' can't be established.
ECDSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no[fingerprint])?

This is because Git uses SSH connection. When SSH connection verifies the Key of GitHub server for the first time, you need to confirm whether the fingerprint information of GitHub Key really comes from GitHub server. Enter yes to enter.

Git will output a warning that you have added GitHub's Key to a local trust list:

Warning: Permanently added 'xx.xx.xx.xx' (ECDSA) to the list of known hosts.

This warning will only appear once, and there will be no warning for subsequent operations.

summary

To associate a remote library, use the command git remote add origin git @ xxxxxxxxxxxxxxxx.git;

After association, use the command git push -u origin --all or git push -u origin master to push all the contents of the master branch for the first time;

After that, after each local submission, you can use the command git push origin master to push the latest changes as long as necessary;

3. Remote warehouse cloning

If you do not want to download from the remote warehouse locally, use the git clone command:

Log in to gitlab, find the corresponding project, click clone, and copy the content under ssh clone:

cd existing_folder
git clone git@10.10.82.53:xsqself/gittest.git

Yes.

Tags: git ssh GitLab github

Posted on Sat, 21 Mar 2020 04:06:09 -0400 by Lodius2000