7

解决 GitHub 每次push时都提示输入用户名和密码的问题

 3 years ago
source link: https://hellodk.cn/post/141
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

解决 GitHub 每次push时都提示输入用户名和密码的问题

每次 push 时都让输入用户名和密码是因为 https 传输时,GitHub 并不会记住用户名和密码,报错信息类似于下面这样:

E:\personal-projects\notes> git push
发送请求时出错。
fatal: HttpRequestException encountered.
发送请求时出错。
Username for 'https://github.com': xxx
Password for 'https://[email protected]':

解决办法就是使用 ssh 来 push 和 pull 而不是 https

  1. git remote -v (查看当前使用的 push 和 fetch 方式)
    ps: pull = fetch + merge
    origin https://github.com/xxx/notes-2020.git (fetch)
    origin https://github.com/xxx/notes-2020.git (push)
  2. 查看到是 https 方式,执行下面语句删除这种连接方式
    git remote rm origin
  3. 去 GitHub 主页找到对应 repository 然后复制其 ssh 的地址
  4. 执行:
    git remote add origin [email protected]:xxx/notes.git
  5. 执行 (master 是远端分支名字,视情况而定)
    git push --set-upstream origin master
  6. git remote -v
    origin [email protected]:xxx/notes.git (fetch)
    origin [email protected]:xxx/notes.git (push)

至此,问题解决。

标签: git

本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK