A detailed tutorial on Git configuration password-free login and common operations (based on the Gitee platform)


foreword

Here I use the project created by vuecli for code management, and the platform I use is Gitee.

In terms of platforms, GitHub is actually the most recommended platform (but it is abandoned due to unstable domestic connections), because GitHub has a function that can directly run your project in the warehouse, which is not available on other platforms. I hope In the future, our platform can also achieve this level.


1. SSH password-free login configuration

The role of SSH key: to realize the encrypted data transmission between the local warehouse and Github without login. Benefits of SSH key: No login authentication, encrypted data transmission.
SSH key consists of two parts, namely:

  1. id rsa (private key file, stored in the client computer)
  2. id rsa.pub (public key file, needs to be configured in Gitee)

1. Install Git

https://git-scm.com/

insert image description hereinsert image description here
Just install it directly

2. Generate SSH

Enter the root directory of the direct project, right click on the blank space, and open Git Bash.
insert image description here
I use the built-in terminal in Vscode, and it can be opened directly by pressing ctrl+~, but note that the directory needs to be under the project root directory

cd (文件名)

insert image description here
You can see it in ls in the root directory.
insert image description here
At this time, you need to pay attention to a file. gitignore
This file is a git configuration file. If there is no file, you can use touch . Here is a default configuration

.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

The files among them represent that these files will not be tracked when git add, especially the dependent file node_modules. This file occupies the largest space in the project. This file does not need to be tracked, so it needs to be blocked. *.suo: means that as long as it is The suffix .suo will be blocked. Here is a knowledge point. Because there is no need to track node_modules, there is no dependency when pulling the project. You need to use npm install to install the dependency before you can run the project.

  • set global name

git config --global user.name "name"

  • Set up a global mailbox

git config --global user.email "Mailbox"

generate local.ssh

Paste the following command, and replace XXX with the email address filled in when registering a Gitee account:

ssh-keygen -t rsa -b 4096 -C "XXX"

Press Enter three times in a row to generate two files, id rsa and id rsa.pub, in the C:Users\username folder.ssh directory

insert image description here

3. Configure SSH key

Open the id rsa.pub file with Notepad and copy the text inside

提示:这里会有一个小坑,在Ctrl+A时可能会复制一个空格出来需要注意一下

Log in to Gitee in the browser, click on the avatar -> Settings -> SSH public key -> fill in the information

insert image description here

4. Verify that the SSH key is configured successfully

ssh -T git@gitee.com

Enter yes
and when this is displayed, it means the configuration is successful!
insert image description here

2. Create a remote warehouse

1. Log in to your Gitee account

https://gitee.com/login

If you don't have an account, you can register directly

2. Create a remote warehouse


insert image description hereI have given a common configuration here for creating a new warehouse . The introduction of the warehouse name can be set by yourself
insert image description hereinsert image description here
. See here to show that the warehouse has been created. The next step is to connect to the remote warehouse to upload the project.

git config --global user.name : set user name
git config --global user.email : set user mailbox
mkdir demo : create file
cd demo : enter file
git init : initialize file directory
touch README.md : create a similar project Indicated file
git add README.md : track the file just created (you don’t have to track this file, any file directory of your own is fine, the purpose is to upload files to the local warehouse next time, if you don’t track any files, you can’t upload them To the local warehouse, it is equivalent to nothing, how to upload? So at least one file must be tracked here)
git commit -m "first commit" : upload to the local warehouse, "first commit": equivalent to a note, it is recommended to Bring them with you when uploading, otherwise you won’t know what the reason for uploading this time is.
git remote add origin XXX : The meaning here is: the address followed by adding a remote warehouse is the address of the remote warehouse, and the name is origin.
git push -u origin "master" : upload the content of the local branch master to origin, -u is only required for the first upload, and can be omitted later


Guess you like

Origin blog.csdn.net/weixin_44748171/article/details/128224747