git clone and git push operation process

Generate personal access token

When using the git push command directly or using HTTPS to perform git clone, an error will be reported. The error message is as follows:

报错:remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see github.blog/2020-12-15-… for more information.
fatal: unable to access 'github.com/sober-orang…': The requested URL returned error: 403

Or the situation shown in the picture below may occur, that is, after entering the command, a window will appear, prompting you to log in with a browser or a password. If you click the browser to log in, a small gray window will appear. Enter the user name and password in sequence, but the login is successful. Afterwards, the git black window appears fatal: A task has been canceled; if you click on the password to log in, a string of verification codes will appear and jump to the web page window. After entering the verification code that just appeared, the web page will appear as shown in the figure. Congratulations, you are all set! is displayed, but the git black window still displays fatal: a task has been cancelled.

The reason for the error messages reported by the two is: Starting from August 13, 2021, github no longer supports the use of password push.

Solution: Two types:
1. Use SSH
2. Use Personal access token

Method 1: Use SSH

Click this link to jump to method details

Method 2: Use Personal access token

First, you need to obtain the token

1. Click on your GitHub avatar -> Settings -> Developer Settings -> Personal access tokens -> Generate new token

2. Generate token

3. Copy the token 4. Use the token to perform push, pull, clone and other operations (the operation principles of pull and clone are the same as push, just replace push with pull or other corresponding commands) The actual principle of using token is to convert the original plain
text Change the password to token. To put it bluntly, token>=password. The reason why I wrote > here is because the function of token is much greater than that of the original password. Compared with password, token has many uses that it does not have.

How to use token

Token method one: push directly

This method requires you to enter the token every time you push.

   # git push https://你的token@你的仓库链接,我这里是我的仓库链接你要改成你的
   git push https://你的[email protected]/sober-orange/study.git
复制代码

Token method two: modify the remote alias

In this way, you can directly specify the alias when pushing.
If you have already set the remote alias, use the following command

# 我这里的别名是origin
# git remote set-url 你的remote别名 https://你的token@你的仓库地址
# git remote set-url origin https://【用户名】:【token】@github.com/用户名/项目名.git

git remote set-url origin https://你的[email protected]/sober-orange/study.git
# 提交代码
git push -u origin master
复制代码

If you have not set an alias, use the following command to add an alias

 # git remote add 别名 https://你的token@你的仓库地址
 git remote add origin https://你的[email protected]/sober-orange/study.git
 # 提交代码
 git push -u origin master
复制代码

Token method three: Use Git Credential Manager Core (GCM Core) to remember the token

git push
Username: 你的用户名
Password: 你的token
# 记住token
git config credential.helper store
复制代码

TOekn Method 4: Use Windows Credential Manager

  1. Open Credential Manager -> Windows Credentials
  2. Find the entry for "git: github.com " and edit it
  3. Replace your previous password with token

push command details

The git push command is used to push updates from local branches to the remote host. Its format is similar to the git pull command.

git push <远程主机名> <本地分支名>:<远程分支名>
复制代码

Note: There must be no spaces before and after: here. \colorbox{cyan}{Note: There must be no spaces before and after : here. }Note: There must be no spaces before and after : here.

Note that the branch push order is written as <source>:<destination>,
so git pull is <remote branch>:<local branch>,
and git push is <local branch>:<remote branch>.

If the remote branch name is omitted, it means that the local branch will be pushed to the remote branch that has a "tracking relationship" with it (usually both have the same name). If the remote branch does not exist, it will be created.

git push origin master
复制代码

The above command means pushing the local master branch to the master branch of the origin host. If the latter does not exist, it will be created. (After opening git on the local folder that needs to be uploaded, and using the git init command to generate the .git file, the folder defaults to the master branch)

If the local branch name is omitted, it means that the specified remote branch is deleted, because this is equivalent to pushing an empty local branch to the remote branch.

git push origin :master
# 等同于
git push origin --delete master
复制代码

The above command means to delete the master branch of the origin host.

If there is a tracking relationship between the current branch and the remote branch, both the local branch and the remote branch can be omitted.

git push origin
复制代码

The above command indicates that the current branch will be pushed to the corresponding branch of the origin host.

If the current branch has only one tracking branch, the hostname can be omitted.

git push
复制代码

If the current branch has a tracking relationship with multiple hosts, you can use the -u option to specify a default host, so that you can use git push without adding any parameters later.

git push -u origin master
复制代码

The above command pushes the local master branch to the origin host and specifies origin as the default host. You can then use git push without adding any parameters.

git push operation process

# 1、(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库
    git init
# 2、把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点“.”,意为添加文件夹下的所有文件
   git add .
# 3、用命令 git commit告诉Git,把文件提交到仓库。引号内为提交说明
   git commit -m 'first commit'
# 4、关联到远程库 即使用如下命令添加别名
  git remote add origin 你的远程库地址
# 5、使用token登录
   git remote set-url origin https://【用户名】:【token】@github.com/用户名/项目名.git
# 6、把本地库的内容推送到远程,使用 git push命令,实际上是把当前分支master推送到远程。执行此命令后会要求输入用户名、密码,验证通过后即开始上传。
 git push -u origin master:远程分支名
复制代码

Note: After using the commit command in git, the Author identity unknown
error message is displayed as follows:

*** Please tell me who you are.
Run  
git config --global user.email "[email protected]"  
git config --global user.name "Your Name" to set your account's default identity.
Omit --global to set the identity only in this repository. fatal:
unable to auto-detect email address (got 'Zero@zero.(none)')
复制代码

Re-enter the command in the git command line:
first enter: git config --global user.name "your name"
and press Enter,
then enter: git config --global user.email "your email address"
before submitting. That's no problem.

git clone process

git clone https://[email protected]/username/xxx.git
复制代码

git related commands

Supongo que te gusta

Origin blog.csdn.net/weixin_54106682/article/details/126860371
Recomendado
Clasificación