简体   繁体   English

如何在 VS 代码中将 Github 推/拉从用户/传递切换到 SSH

[英]How do I switch Github Push/Pull from user/pass to SSH in VS Code

I got an email from Github saying that they are deprecating user/pass authentication for git operations next summer.我从 Github 收到 email 说他们明年夏天将弃用 git 操作的用户/通过身份验证。 user/pass was what was using inside VSCode to push/pull. user/pass 是 VSCode 内部用来推/拉的。

I set up my SSH and added it to my github account.我设置了我的 SSH 并将其添加到我的 github 帐户中。 And I can connect from the command line properly:我可以从命令行正确连接:

sean@sean-ThinkPad-T480:~/.ssh$ ssh -T git@github.com
Hi seanrasmussen! You've successfully authenticated, but GitHub does not provide shell access.

However, when I push/pull with VSCode's GUI, I think it is still using the old way.但是,当我使用 VSCode 的 GUI 推/拉时,我认为它仍在使用旧方式。 Not SSH.不是 SSH。 How do I force SSH instead in the VSCode GUI?如何在 VSCode GUI 中强制使用 SSH?

Thanks!谢谢!

This has nothing to do with VS Code.这与 VS Code 无关。 The URL of the remote repository is stored in your local repository.远程仓库的 URL 存储在本地仓库中。

  1. Open a command-line/shell and cd to your code.打开命令行/shell 并 cd 到您的代码。

  2. Then, check the current remote URL:然后,查看当前远程URL:

    git remote -v

    The result looks probably similar to this:结果可能与此类似:

> origin  https://github.com/YOUR_GIHUB_USERNAME/YOUR_REPO_NAME.git (fetch)
> origin  https://github.com/YOUR_GIHUB_USERNAME/YOUR_REPO_NAME.git (push)
  1. Change the URL to ssh:将 URL 更改为 ssh:

    git remote set-url origin git@github.com:YOUR_GIHUB_USERNAME/YOUR_REPO_NAME.git

  2. (optionally) Check the remote URL again (it should now return the new URL): (可选)再次检查远程 URL(它现在应该返回新 URL):

    git remote -v

Now git will fetch/pull from/push to this new URL.现在 git 将从这个新的 URL 获取/拉取/推送。 This includes any git integrations into editors, IDEs, or git GUI clients.这包括任何 git 集成到编辑器、IDE 或 git GUI 客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM