我需要更改远程存储库的 url,所以我正在查看https://git-scm.com/docs/git-remote上的文档,但是当我这样做时:
git remote set-url git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
我收到消息 usage: git remote set-url [--push] <name> <newurl> [<oldurl>]
我不太明白,我应该输入:
git remote set-url --push gitusername git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
或者代表什么<name>?我应该包括旧网址吗?
更新
所以当我输入:
git remote set-url --push origin git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
在那种类型之后 git remote -v
我明白了:
origin git@github.com:oldusername/oldrepo.git (fetch)
origin git@github.com:gitusername/repository.git (push)
Run Code Online (Sandbox Code Playgroud)
如何更改提取?
cmb*_*ley 10
您需要为现有遥控器设置 URL:
git remote set-url origin git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
使用上面的命令将更新获取和推送 URL。
使用--push只会更新推送 URL:
git remote set-url --push origin git@github.com:gitusername/repository.git
git remote -v
origin git@github.com:oldusername/oldrepo.git (fetch)
origin git@github.com:gitusername/repository.git (push)
Run Code Online (Sandbox Code Playgroud)
在这一点之后,现在有一个单独的条目.git/config:
[remote "origin"]
url = git@github.com:oldusername/oldrepo.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
现在,因为有单独的条目,使用set-urlwithout--push只会更新 fetch,而不是两者:
git remote set-url origin git@github.com:thirdusername/thirdrepository.git
git remote -v
origin git@github.com:thirdusername/thirdrepository.git (fetch)
origin git@github.com:gitusername/repository.git (push)
Run Code Online (Sandbox Code Playgroud)
如果你想回到原来的状态,你可以从 中删除pushurl条目.git/config,或者使用set-url --delete --push:
git remote set-url --delete --push origin git@github.com:gitusername/repository.git
Run Code Online (Sandbox Code Playgroud)
在此之后,调用set-urlwithout--push应该返回更改推送和获取 URL。