[英]How do I rename a git remote?
我目前有一个名为heroku
的 git 遥控器,我想将其重命名为production
。
$ git remote -v
heroku https://git.heroku.com/example.git (fetch)
heroku https://git.heroku.com/example.git (push)
$ git remote rename <old-name> <new-name>
所以,对于这个例子:
$ git remote rename heroku production
这里有用的文档: https ://help.github.com/articles/renaming-a-remote/
请注意,在 Git 2.11 之前, git remote rename
可能会尝试重命名不存在的遥控器!
这已在 Git 2.12(2017 年第一季度)中得到修复:参见Johannes Schindelin ( dscho
)的commit e459b07和commit af5bacf (2017 年 1 月 19 日)。
(由Junio C Hamano -- gitster
--在提交 fe575f0中合并,2017 年 1 月 31 日)
remote rename
:更仔细地确定是否配置了远程通过对
~/.gitconfig
中定义的远程进行预期调整(例如,“remote.origin.prune
”设置为true
,即使在特定的 Git 存储库中可能实际上定义了“origin
”远程),“git remote rename
”和其他命令被误解并表现得好像这样一个不存在的遥控器确实存在。
在 Git 2.26(2020 年第一季度)中,“ git remote
rename XY
”需要调整以前为X
到Y
的配置变量(例如branch.<name>.remote
)。
branch.<name>.pushRemote
现在也更新了。
请参阅Bert Wesarg ( bertwesarg
)的提交b3fd6cb (2020 年 2 月 1 日)和提交 f2a2327 、 提交 923d4a5 、 提交 ceff1a1 、 提交 1a83068 、 提交 88f8576 (2020 年 1 月 27 日)。
(由Junio C Hamano -- gitster
--在提交 d0038f4中合并,2020 年 2 月 25 日)
remote rename/remove
:处理分支..pushRemote 配置值签字人:Bert Wesarg
重命名或删除遥控器时
git remote rename XY git remote remove X
Git 已经重命名/删除了任何配置值
branch.<name>.remote = X
至
branch.<name>.remote = Y
由于 branch..pushRemote 也命名了一个远程,它现在也重命名或删除这些配置值
branch.<name>.pushRemote = X
至
branch.<name>.pushRemote = Y
和:
remote rename/remove
:轻轻处理remote.pushDefault
配置签字人:Bert Wesarg
重命名遥控器时
git remote rename XY git remote remove X
Git 已重命名或删除任何
branch.<name>.remote
和分支。<name>.pushRemote
配置,如果它们的值为X
。然而
remote.pushDefault
需要一种更温和的方法,因为这可以在非 repo 配置文件中设置。
在这种情况下,只会打印一条警告,例如:warning: The global configuration remote.pushDefault in: $HOME/.gitconfig:35 now names the non-existent remote origin
它被更改为
remote.pushDefault = Y
或在 repo 配置中设置时被删除。
一个常见的用例是将origin
切换到您的 fork 并将当前origin
重命名为upstream
。
一个简单的远程重命名将使pushDefault
和branch
配置值指向重命名的远程,而不是通常预期的原点。 如果你这样做,那么这个流程将工作得最好......
首先获取当前origin
:
git remote -v
记录值( OLD_URL
),现在使用set-url
更改它,然后将旧origin
添加为新upstream
:
git remote set-url origin NEW_URL
git remote add upstream OLD_URL
当您链接并在答案中说自己时,您只需输入
git remote rename heroku production
见页面底部: https ://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.