更改上游url
你想更改 Git 仓库的 上游(remote)GitHub 地址,其实就是修改 origin 或其他 remote 指向新的仓库 URL。可以按下面步骤操作:
1. 查看当前 remote
输出示例:
1 2
| origin https://github.com/旧用户名/旧仓库.git (fetch) origin https://github.com/旧用户名/旧仓库.git (push)
|
2. 修改远程仓库地址
方法 A:直接修改已有 remote(推荐)
1
| git remote set-url origin https://github.com/新用户名/新仓库.git
|
方法 B:先删除再添加
1 2
| git remote remove origin git remote add origin https://github.com/新用户名/新仓库.git
|
3. 验证修改
输出应显示新的 GitHub 地址:
1 2
| origin https://github.com/新用户名/新仓库.git (fetch) origin https://github.com/新用户名/新仓库.git (push)
|
4. 推送到新仓库
如果你想把本地分支推送到新仓库:
注意:如果你的分支不是 main,把 main 换成你自己的分支名。