如何将推举/遥控器推向新的起源? [英] Push refs/remotes to new origin, how?
问题描述
我有一个指向远程的存储库,现在我创建了一个新的远程,例如,使用 git remote set-url origin myNewRemote
更改了原始URL。然后我做了一个 git push
但由于push只推送本地分支,我仍然需要将远程分支推送到新的远程。我知道这不是实践,但我现在要做的就是告诉新的远程嘿,这里是你应该知道的远程分支然后我将通过正常的Git工作流,在那里创建本地分支/跟踪并将它们推送到远程的,但现在我正在过渡到回到我以前的移动到新的远程。
我记得做过这样的事情一次:
git push origin refs / remotes / *:refs / heads / *
但它们会被错误地创建,所以我将原点追加到分支名称,所以我很确定上面的命令(X:Y部分)不完全正确,有人可以帮助正确的,所以我不必先在本地创建所有分支?
donnib
< blockquote>
git push origin refs / remotes / *:refs / heads / *
非常接近。由于旧的和新的 远程
名称都是 origin
,远程跟踪分支 - 那些在 refs / remotes /
下的名字特别在 refs / remotes / origin /
子名称空间中,你也想放弃额外的 origin /
。因此,你想要的是:
git push originrefs / remotes / origin / *:refs / heads / *
(我在这里添加了引号,作为防止外壳的保护装置,它们喜欢在
早餐的字符:-)更严重的是,shell的规则是像 *
和这样的globbing字符。
和 [az]
等等都有点复杂,并且更加明智的shell像 sh $ c $如果它们没有匹配任何文件,但是这会导致偶然的问题,当您实际上有一个名为<$ c的文件时
)。
I have a repository which was pointing to an remote and now i made a new remote e.g the origin url has changed using git remote set-url origin myNewRemote
. I then did a git push
but since push only pushes local branches i still need to push the remote branches to the new remote. I know this is not practice but all i want to do now is tell the new remote "hey here are your remote branches you should know about" then i will go thru normal Git workflow where i create local branches/tracked and push those to the remote but right now i am in a transition to get back to what i had before moving to the new remote.
I remember doing something like this once :
git push origin refs/remotes/*:refs/heads/*
but they get created wrongly so i get origin appended to the branch names so i am pretty sure the command above (the X:Y part) is not entirely correct, can somebody help with the right one so i don't have to create all branches locally first ?
donnib
What you recall:
git push origin refs/remotes/*:refs/heads/*
is very close. Since both the old and new remote
name is origin
, the remote-tracking branches—those names under refs/remotes/
—are specifically in the refs/remotes/origin/
sub-name-space, and you want to discard the extra origin/
as well. Hence what you want is:
git push origin "refs/remotes/origin/*:refs/heads/*"
(I added the quotes here as a protective device against the shells, which like to munch on *
characters for breakfast. :-) More seriously, the shell rules for globbing—characters like *
and ?
and [a-z]
and such—are a bit complicated, and the more sensible shells like sh
and bash
pass them on unchanged if they match no files, but this causes the occasional problem when you actually have a file named refs/remotes/origin/foo:refs/heads/bar
for instance.)
这篇关于如何将推举/遥控器推向新的起源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!