【Git】更改遠程倉庫的URL
git remote set-url 命令可更改現有遠程倉庫的 URL。
將遠程 URL 從 SSH 切換到 HTTPS
- 打開 Git Bash。
- 將當前工作目錄更改為您的本地倉庫。
- 列出現有遠程倉庫以獲取要更改的遠程倉庫的名稱。
$ git remote -v > origin git@github.com:USERNAME/REPOSITORY.git (fetch) > origin git@github.com:USERNAME/REPOSITORY.git (push) - 使用
git remote set-url命令將遠程的 URL 從 SSH 更改為 HTTPS。$ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git - 驗證遠程 URL 是否已更改。
$ git remote -v # Verify new remote URL > origin https://github.com/USERNAME/REPOSITORY.git (fetch) > origin https://github.com/USERNAME/REPOSITORY.git (push)
下次對遠程倉庫執行 git fetch、git pull 或 git push 操作時,您需要提供 GitHub 用戶名和密碼。 當 Git 提示您輸入密碼時,請輸入您的個人訪問令牌 (PAT)。 基于密碼的身份驗證對 Git 已棄用,使用 PAT 更安全。 更多信息請參閱“創建個人訪問令牌”。
您可以使用憑據小助手讓 Git 在每次與 GitHub 會話時記住您的 GitHub 用戶名和個人訪問令牌。
將遠程 URL 從 HTTPS 切換到 SSH
- 打開 Git Bash。
- 將當前工作目錄更改為您的本地倉庫。
- 列出現有遠程倉庫以獲取要更改的遠程倉庫的名稱。
$ git remote -v > origin https://github.com/USERNAME/REPOSITORY.git (fetch) > origin https://github.com/USERNAME/REPOSITORY.git (push) - 使用
git remote set-url命令將遠程的 URL 從 HTTPS 更改為 SSH。$ git remote set-url origin git@github.com:USERNAME/REPOSITORY.git - 驗證遠程 URL 是否已更改。
$ git remote -v # Verify new remote URL > origin git@github.com:USERNAME/REPOSITORY.git (fetch) > origin git@github.com:USERNAME/REPOSITORY.git (push)
浙公網安備 33010602011771號