如何将所有分支推送到新创建的存储库?

时间:2018-06-20 16:00:22

标签: git github gitlab push git-push

说明

我有一个 GitLab 存储库,其中的分支为devmastergithub-snapshot,分支为许多 tags

我们想开源,我们编写了一个小脚本,该脚本创建了GitHub存储库,并将整个项目推入了

脚本在Gitlab-CI上运行,在此期间,使用${CI_COMMIT_REF_NAME}头部处于分离状态 (提交哈希)。

此外,我们希望最后不要在GitHub存储库上推送分支github-snapshot

创建GitHub存储库后,脚本按顺序执行:

  1. 创建新遥控器 github
  2. 将所有branches推到github
  3. 将所有tags推到.github
  4. 从远程github-snapshot删除分支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 <remote> --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,

问题

  1. 考虑到我处于分离状态,如何将所有分支推送到新创建的存储库?

我的第一个想法是检出一个像master这样的真实分支,但这需要再次检查以查看master是否存在。我想知道是否有更合适的方法。

1 个答案:

答案 0 :(得分:0)

要推送所有分支,请使用其中一个(将REMOTE替换为远程名称,例如“ origin”):

git push REMOTE '*:*'
git push REMOTE --all
To push all your tags:

git push REMOTE --tags

最后,我认为您可以使用以下命令在一个命令中完成所有操作:

git push REMOTE --mirror

但是,除了--mirror之外,它还会推动您的遥控器,因此这可能并不是您想要的。