git 使用 access token

  1. 申请token

  2. .git/config文件中修改

修改前:

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = https://github.com/<username>/proj.git
	fetch = +refs/heads/*:refs/remotes/origin/*

修改后:

[user]
	name = <username>
	email = <email>
[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = https://<username>:<access token>@github.com/<username>/proj.git
	fetch = +refs/heads/*:refs/remotes/origin/*

不需要换提交人的话,可以把[user]去掉


使用token去clone私有仓库:

git clone https://oauth2:<token>@github.com/<username>/proj.git
posted @ 2022-09-25 17:32  Ajanuw  阅读(811)  评论(0编辑  收藏  举报