【问题标题】:Import into GitLab a git project including all branches将包含所有分支的 git 项目导入 GitLab
【发布时间】:2021-02-23 05:05:03
【问题描述】:

我在 Synology nas 中有一个 git 服务器。现在我已经将 gitlab 安装到了一个新服务器中,我想在其中导入我的所有存储库。据我所知,我必须从我的 git 服务器克隆每个存储库并手动将它们一一导入。所以我开始克隆我的存储库:

git clone ssh://usuario@servidor/ruta/repositorio.git repositorio

然后我进入存储库文件夹,为新服务器添加一个新的远程并推送:

cd repositorio
git remote rename origin origin-git
git remote add origin ssh://git@gitlab/url/repository.git
git push -u origin --all
git push -u origin --tags

现在我到了我的 gitlab,我可以看到我的 master 分支及其所有提交。我还可以看到其他提交,但我的问题是它们没有分配给任何分支。

在这里你可以看到 gitlab 生成的提交图形。应该还有另一个分支,叫做 desarrollo。

如果我尝试从 Gitlab 克隆此存储库,我将看不到所有这些提交,因为唯一现有的分支是 master。

编辑:添加git fetch --allgit pull --all 没有任何区别。

【问题讨论】:

标签: git gitlab


【解决方案1】:

添加 git fetch --allgit pull --all 根本不起作用。它不加载除 master 之外的任何其他分支。您可以使用git branch 查看本地分支,使用git branch -a 查看本地和远程分支。

解决方案是跟踪所有分支,为此添加一些代码,然后在重命名原点之前运行它:

# Track all branches
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
    git branch --track "${branch##*/}" "$branch"
done
# Pull fetched branches, just in case
git fetch --all
git pull --all

然后像往常一样重命名 origin,然后推送所有内容。

git remote rename origin origin-git
git remote add origin ssh://git@gitlab/url/repository.git
git push -u origin --all
git push -u origin --tags

完成所有这些后,您可以检查 gitlab,您会看到所有分支都已同步。

获取此处看到的所有分支的解决方案:How to fetch all Git branches

【讨论】:

  • 我还在阅读另一个答案——我经历了和你一样的事情,我想知道我是否可以在事后从我的原始仓库中引入分支,因为我的新主回购现在有原始回购中没有的变化。我想我不会为了一件事而使用 --all。
  • 如果你已经推送了新的提交,我认为你不能添加那些旧的提交。您所能做的就是创建一个新分支并将您的旧提交推送到那里。此外,您可以创建一个新的仓库,先添加旧提交,然后添加新提交。
猜你喜欢
  • 2013-12-20
  • 2020-08-23
  • 2022-11-27
  • 1970-01-01
  • 1970-01-01
  • 2015-06-14
  • 1970-01-01
  • 1970-01-01
  • 2014-02-28
相关资源
最近更新 更多