git:在遥控器之间克隆时保持分支名称和路径相同

发布于 2025-02-06 12:15:42 字数 1405 浏览 0 评论 0原文

如何在保持分支名称和路径一致的gitlab服务器之间克隆存储库?

我将以下序列用于GitLab服务器之间的克隆存储库,中间是本地GIT客户端:

git clone <source URL>
for /F %R in ('git branch -r') do git branch --track %R %R
git fetch --all
git pull --all
git fetch --tags
git remote rm origin
git remote add origin <target URL>
git push --all
git push --tags

但是此序列会更改分支路径并创建源服务器上不存在的分支。

说我在源gitlab中有一个带有2个分支的仓库:(

* branch1
  branch2

在此处和下方标记默认分支)

当我用git git clone clone a reco reco 时,我得到了两个额外的分支,相关的分支在源服务器上的默认一个:

* branch1
  remotes/origin/HEAD -> origin/branch1
  remotes/origin/branch1
  remotes/origin/branch2

git granch - track分支的数量增长到7:

* branch1
  origin/HEAD
  origin/branch1
  origin/branch2
  remotes/origin/HEAD -> remotes/origin/branch1
  remotes/origin/branch1
  remotes/origin/branch2

更多,新的Head Branch(Origin/Head)与Branch1分支的任何一个无关。

最后,当我删除旧的原点并添加新的原点时,我会得到:

* branch1
  origin/HEAD
  origin/branch1
  origin/branch2

这正是将其推向目标gitlab服务器的内容。一个分支具有两个重复('Branch1','Origin/Branch1'和“ Origin/Head”),另一个分支更改了它的路径('Branch2' - &gt;'Origin/Branch2')。

在这里,我可以删除“额外”分支,然后将所有分支重命名为所有分支,然后将其推向目标服务器。但是,当存储库中有数百个分支时,这会成为头痛。

尽管在推动之前,我可以写一个脚本以从所有这些分支的名称中删除“原始/”,但我觉得自己想发明一辆自行车。是否有一种更简单的方法可以在目标gitlab中获得与源吉特拉布完全相同的分支名称?

How do I clone repositories between GitLab servers keeping branch names and paths consistent?

I use the following sequence to clone repositories between GitLab servers, with local git client in the middle:

git clone <source URL>
for /F %R in ('git branch -r') do git branch --track %R %R
git fetch --all
git pull --all
git fetch --tags
git remote rm origin
git remote add origin <target URL>
git push --all
git push --tags

But this sequence changes branch paths and creates branches that did not exist on the source server.

Saying I have a repo in source GitLab with 2 branches:

* branch1
  branch2

(here and below the star marks the default branch)

when I clone a repo to my local machine with git clone, I got two extra branches, related to the default one at the source server:

* branch1
  remotes/origin/HEAD -> origin/branch1
  remotes/origin/branch1
  remotes/origin/branch2

After git branch --track the number of branches grows to 7:

* branch1
  origin/HEAD
  origin/branch1
  origin/branch2
  remotes/origin/HEAD -> remotes/origin/branch1
  remotes/origin/branch1
  remotes/origin/branch2

More, new HEAD branch (origin/HEAD) is not related to any of branch1 branches anymore.

Finally, when I remove old origin and add a new one, I get:

* branch1
  origin/HEAD
  origin/branch1
  origin/branch2

And this is exactly what will be pushed to the target GitLab server. With one branch having two duplicates ('branch1', 'origin/branch1' and 'origin/HEAD'), and another one changed it's path ('branch2' -> 'origin/branch2').

Here I can delete 'extra' branches and rename all branches manually before pushing them to the target server. But this becomes a headache when there are hundreds of branches in a repo.

Though I can write a script to remove 'origin/' from names of all these branches before pushing, I feel like inventing a bicycle. Is there an easier way to get branch names in target GitLab exactly the same as they were in the source GitLab?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜深人未静 2025-02-13 12:15:42

免责声明:托雷克(Torek)的所有凭证,他们在评论中描述了适当的方法,而不是在答案中。但是我知道,您寻求答案的人首先要寻找接受的答案。 ;)

so, - mirror参数可以完成作业,序列是:

git clone <source URL> --mirror
<here you might want to copy it to some new subfolder>
git remote rm origin
git remote add origin <target URL>
git push origin --mirror

Disclaimer: all credentials to torek who described the proper approach in a comment, not in an answer. But I know that you guys who seek for answers look for accepted answers first. ;)

So, the --mirror parameter does the job, and the sequence is:

git clone <source URL> --mirror
<here you might want to copy it to some new subfolder>
git remote rm origin
git remote add origin <target URL>
git push origin --mirror
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文