通过 access_token 从 github clone 代码

对于 public 的代码不需要用户相关的信息就可以 clone,但是对于 private 的项目必须要有用户相关信息才可以 clone 或者 pull,在一些脚本中也不可能把用户名密码写进去,所以就有了 access_token。

获取 access_token

点击 https://github.com/settings/tokens 点击右上方的 Generate new token 按钮生成一个 token。

注意

  1. 在生成 token 的时候,需要选中 repo 选项,不然 git clone 的时候会失败。
  2. 生成的 token 需要像密码一样妥善保管,因为离开该页面,就无法在看到 token 了。

参照 : https://help.github.com/cn/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line

git 使用 access_token clone 代码

clone 命令 :

git clone https://<access_token>@github.com/xx.git

例如:
git clone https://1737a2a66d27524992499242f2@github.com/username/projectName.git
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
GitHub token是一种用于身份验证的令牌,用于替代传统的用户名和密码进行登录。生成自己的token可以通过以下步骤进行操作:首先登录到GitHub账号,然后在个人设置中找到"Developer settings",在左侧导航栏中选择"Personal access tokens",点击"Generate new token"按钮,然后根据需要选择相应的权限和范围,最后点击"Generate token"按钮生成token。生成的token可以用于各种GitHub操作,比如克隆仓库、推送代码等。在使用token进行克隆仓库时,可以使用以下命令:$ git clone https://github.com/username/repo.git Username: your_username Password: your_token \[2\]。另外,可以使用git remote命令来查看自己的url,使用git branch -v命令来查看自己的分支,使用git remote set-url <your_url> https://<your_token>@github.com/<username>/<repo>.git来更新自己的url \[3\]。通过使用token进行身份验证,可以提高账号的安全性,并且方便进行各种GitHub操作。 #### 引用[.reference_title] - *1* *3* [github不能使用账户密码登陆了? githubtoken使用(超详细)](https://blog.csdn.net/qq_42915526/article/details/122362565)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [githubtoken使用方法](https://blog.csdn.net/chengwenyang/article/details/120060010)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值