VSCode remotely connects to Gitee

1. Introduction to gitee

Gitee (code cloud) is a Git-based code hosting service launched by Open Source China (OSChina)

https://gitee.com

GitHub: GitHub is the world's largest code hosting platform. More than 50 million developers are using it.

2. Prepare

Insert image description here
Insert image description here

  • Create a backup warehouse on gitee, with a random name

3. Generate ssh public key

  • After installing git, find the installation location of the git folder

Insert image description here

  • Run git.bash.exe and enter the following code. If gitee does not bind an email address, you need to bind an email address.
ssh-keygen -t rsa -C "这里填写你git上面绑定的邮箱"
  • Then press Enter. Under normal circumstances, the following code will appear. If not, check whether you entered it incorrectly.
Generating public/private rsa key pair...
  • Press Enter three times in a row to generate the ssh key.

  • The generated public key can be viewed in id_rsa.pub in 'C drive -> User -> <Account on your own computer> ->.ssh'. id_rsa.pub can be opened using vscode.

  • Insert image description here

Insert image description here

4. Add public key

  • Open your gitee, find the settings, and find the ssh public key in the settings column

Insert image description here

5. Initialize git

  • First go back to the git-bash.exe command window

  • Enter the following command:

  • git config --global user.name 你的gitee仓库名字  
    git config --global user.email 你的gitee绑定的邮箱
    
  • The name of the warehouse can be viewed in the settings and personal space address of the profile.

Insert image description here

6. Associated with remote warehouse

  • Go back to your git warehouse, open the first created warehouse, I created a test warehouse here, and then copy the address of the warehouse

Insert image description here

  • Open vscode and clone this repository to the folder you want to put it in

Insert image description here

  • I put it here in my VScode-Gitee workspace. If you want to put it elsewhere, you can also right-click in other folders and open it in the integrated terminal and enter the following commands.

Insert image description here

  • After the cloning is completed, you will find that there is an additional test folder under your folder. This folder is the remote warehouse on your gitee

Insert image description here

  • In fact, you can also manually add the local warehouse locally, then open the local warehouse folder in the resource manager, right-click Git Bash Here (this option is available after installing git), and then use the command line to connect the local warehouse and the remote warehouse. The premise is that your code cloud has a remote warehouse with the same name as the local warehouse. I use warehouse cloning here to save the process of using the command line to connect.

7. Push updated code

  • After connecting the local warehouse and the remote warehouse, you can submit the locally modified code to the code cloud at any time.
  • First, I added a test.txt file under test. At this time, you will find a 1 appears in the source code management column on the left, the folder turns green, and a U appears on the right side of the newly created test.txt file, which means Update, that is, update.
    Insert image description here
  • Then we opened the source code management bar and found that the test.txt file we just added appeared under the test warehouse. All modified content under the test folder will appear here.
  • Then click the + sign behind the modified file, and then click the √ on the right side of the test warehouse, and then a dialog box will pop up. The content entered in the dialog box is the remarks for this remote submission, and then press Enter

Insert image description here

Insert image description here

  • Then click on the right side of the test warehouse ···and click Push

Insert image description here

  • At this time, when we return to the code cloud warehouse, we will find the file we just submitted

Insert image description here

8. Pull the remote warehouse code

  • When the contents of our warehouse on the code cloud are modified on vscode on a non-local device, and we need to copy the code on the code cloud to the local machine, we need to use the pull function.
  • For example: I manually deleted the test.txt file on Code Cloud. At this time, the code on Code Cloud is inconsistent with that of our local warehouse.

Insert image description here

  • At this time we return to vscode, click on the test warehouse of source code management ···, and click on pull

Insert image description here

  • After pulling, the test.txt of the local warehouse test will also be deleted.

Insert image description here

9. Remove remote connection

  • If we don't want the local test warehouse to remotely connect to the test on the code cloud now, we can find the .git file in the local test warehouse directory. This file is a hidden file. You need to check the check box in the view in the resource manager to view hidden files. Then delete it so that the modified content in the local test repository will not appear in source code management.

Insert image description here

The above are some basic usages of vscode connecting to gitee.

Guess you like

Origin blog.csdn.net/qq_45099813/article/details/120047149