Git 如何将所有分支推送到新创建的存储库? 描述
我有一个带有分支Git 如何将所有分支推送到新创建的存储库? 描述,git,github,gitlab,push,git-push,Git,Github,Gitlab,Push,Git Push,我有一个带有分支dev、master的GitLab存储库,以及带有许多标签的github快照 我们希望开源,我们编写了一个小脚本,该脚本创建了GitHub存储库,并推动整个项目 脚本在Gitlab CI期间运行,在此期间,头处于分离状态,使用${CI\u COMMIT\u REF\u NAME}(提交散列) 此外,我们希望在最后不要将分支github快照放在github存储库中 创建GitHub存储库后,脚本按顺序执行: 创建新远程github 将所有分支推送到github 将所有标记推送到.g
dev
、master
的GitLab存储库,以及带有许多标签的github快照
我们希望开源,我们编写了一个小脚本,该脚本创建了GitHub存储库,并推动整个项目
脚本在Gitlab CI期间运行,在此期间,头处于分离状态,使用${CI\u COMMIT\u REF\u NAME}
(提交散列)
此外,我们希望在最后不要将分支github快照放在github存储库中
创建GitHub存储库后,脚本按顺序执行:
创建新远程github
将所有分支
推送到github
将所有标记推送到.github
从远程github
删除分支github快照
繁殖
步骤(2)失败了,我就是这样做的
git -C ${path} push ${origin} --all
它会产生以下错误:
[ERROR] Command failed: /bin/sh -c git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar push github --all
warning: refname '93a9252c263da35b2fdc6a7ca78ca18083ac5951' is ambiguous.
Git normally never creates a ref that ends with 40 hex characters
because it will be ignored when you just specify 40-hex. These refs
may be created by mistake. For example,
git checkout -b $br $(git rev-parse ...)
where "$br" is somehow empty and a 40-hex ref is created. Please
examine these refs and maybe delete them. Turn this message off by
running "git config advice.objectNameWarning false"
remote: error: GH002: Sorry, branch or tag names consisting of 40 hex characters are not allowed.
remote: error: Invalid branch or tag name "93a9252c263da35b2fdc6a7ca78ca18083ac5951"
To https://[crypted]@github.com/bootstrap-styled/navigation-bar.git
! [remote rejected] 93a9252c263da35b2fdc6a7ca78ca18083ac5951 -> 93a9252c263da35b2fdc6a7ca78ca18083ac5951 (pre-receive hook declined)
! [remote rejected] github-snapshot -> github-snapshot (pre-receive hook declined)
! [remote rejected] gitlab-to-github -> gitlab-to-github (pre-receive hook declined)
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://[crypted]@github.com/bootstrap-styled/navigation-bar.git'
[ERROR] Command failed: /bin/sh -c git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar push github --all
warning: refname '93a9252c263da35b2fdc6a7ca78ca18083ac5951' is ambiguous.
Git normally never creates a ref that ends with 40 hex characters
because it will be ignored when you just specify 40-hex. These refs
may be created by mistake. For example,
git checkout -b $br $(git rev-parse ...)
where "$br" is somehow empty and a 40-hex ref is created. Please
examine these refs and maybe delete them. Turn this message off by
running "git config advice.objectNameWarning false"
remote: error: GH002: Sorry, branch or tag names consisting of 40 hex characters are not allowed.
remote: error: Invalid branch or tag name "93a9252c263da35b2fdc6a7ca78ca18083ac5951"
To https://[crypted]@github.com/bootstrap-styled/navigation-bar.git
! [remote rejected] 93a9252c263da35b2fdc6a7ca78ca18083ac5951 -> 93a9252c263da35b2fdc6a7ca78ca18083ac5951 (pre-receive hook declined)
! [remote rejected] github-snapshot -> github-snapshot (pre-receive hook declined)
! [remote rejected] gitlab-to-github -> gitlab-to-github (pre-receive hook declined)
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://[crypted]@github.com/bootstrap-styled/navigation-bar.git'
评论
对于那些不了解git push--all
如何失败的人,我添加了一些带有git branch-l
的日志:
Remote github configured for GitHub.
Git branch list (git branch -l)
93a9252c263da35b2fdc6a7ca78ca18083ac5951
github-snapshot
gitlab-to-github
* master
[ERROR] Command failed: /bin/sh -c git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar push github --all
warning: refname '93a9252c263da35b2fdc6a7ca78ca18083ac5951' is ambiguous.
Git normally never creates a ref that ends with 40 hex characters
because it will be ignored when you just specify 40-hex. These refs
may be created by mistake. For example,
问题:
我的第一个想法是签出一个真正的分支,比如
master
,但这需要再次检查master
是否存在。如果有更合适的方法,我希望得到通知。要推送所有分支,请使用以下任一方法(将REMOTE替换为REMOTE的名称,例如“origin”):
最后,我认为您可以使用以下命令在一个命令中完成这一切:
git push REMOTE --mirror
然而,另外——mirror也会推送你的遥控器,所以这可能不是你想要的。这与谷歌的第一个答案完全相同。问题是这个命令只能从一个分支运行,否则它会尝试推除其他分支。@BigDong我不明白,为什么
git-push--all
不起作用?我已经编辑了这个问题并为您添加了备注您创建了一个名称非常糟糕的分支,一个名为93a9252c263da35b2fdc6a7ca78ca18083ac5951
的分支。您应该将此分支重命名为更合适的名称,例如,git branch-m 93a9252c263da35b2fdc6a7ca78ca18083ac5951这可能更好
。
git push REMOTE --mirror