我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们
文章版本: Enterprise Server 2.15

此版本的 GitHub Enterprise 将停止服务 此版本的 GitHub Enterprise 已停止服务 2019-10-16. 即使针对重大安全问题,也不会发布补丁。 For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

更改远程仓库的 URL

git remote set-url 命令可更改现有远程仓库的 URL。

提示: 有关 HTTPS 与 SSH URL 之间的差异,请参阅“我应使用哪种远程 URL?

git remote set-url 命令使用两个参数:

将远程 URL 从 SSH 切换到 HTTPS

  1. Open TerminalTerminalGit Bashthe terminal.

  2. 将当前工作目录更改为您的本地仓库。

  3. 列出现有远程仓库以获取要更改的远程仓库的名称。

    $ git remote -v
    > origin  git@主机名:USERNAME/REPOSITORY.git (fetch)
    > origin  git@主机名:USERNAME/REPOSITORY.git (push)
  4. Change your remote's URL from SSH to HTTPS with the git remote set-url command.

    $ git remote set-url origin https://主机名/USERNAME/REPOSITORY.git
  5. 验证远程 URL 是否已更改。

    $ git remote -v
    # Verify new remote URL
    > origin  https://主机名/USERNAME/REPOSITORY.git (fetch)
    > origin  https://主机名/USERNAME/REPOSITORY.git (push)

The next time you git fetch, git pull, or git push to the remote repository, you'll be asked for your GitHub username and password.

Switching remote URLs from HTTPS to SSH

  1. Open TerminalTerminalGit Bashthe terminal.

  2. 将当前工作目录更改为您的本地仓库。

  3. 列出现有远程仓库以获取要更改的远程仓库的名称。

    $ git remote -v
    > origin  https://主机名/USERNAME/REPOSITORY.git (fetch)
    > origin  https://主机名/USERNAME/REPOSITORY.git (push)
  4. Change your remote's URL from HTTPS to SSH with the git remote set-url command.

    $ git remote set-url origin git@主机名:USERNAME/REPOSITORY.git
  5. 验证远程 URL 是否已更改。

    $ git remote -v
    # Verify new remote URL
    > origin  git@主机名:USERNAME/REPOSITORY.git (fetch)
    > origin  git@主机名:USERNAME/REPOSITORY.git (push)

疑难解答

You may encounter these errors when trying to change a remote.

No such remote '[name]'

This error means that the remote you tried to change doesn't exist:

$ git remote set-url sofake https://主机名/octocat/Spoon-Knife
> fatal: No such remote 'sofake'

检查您是否正确键入了远程仓库的名称。

延伸阅读

问问别人

找不到要找的内容?

联系我们