git 使用技巧

push时报错:

git push origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com

如下解决:

在远程主机生成 ssh key 文件

ssh-keygen -t rsa

然后把文件

/root/.ssh/id_rsa.pub

的内容添加到 github 的工程对应开发者 key 里面保存。

修改git配置

编辑

.git/config

文件,修改:

url = https://github.com/user/test.git,

url = ssh://git@github.com/user/test.git

然后再次 push 即可。

This entry was posted in DEVOPS. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Both comments and trackbacks are currently closed.

1 Comment

  1. cme
    Posted 2018年7月16日 at 下午2:37 | Permalink

    如果要用API进行开发,可以先获取到自己的token, 然后再调用 curl 或者 http 库进行访问:

    curl --header "PRIVATE-TOKEN: 60XXXXXXXXX" -s "https://api.github.com/repos/testuser/tools"