logzly. GitForge Insights

GitHub to GitLab Migration: Preserve History in 8 Steps

Read this article in clean Markdown format for LLMs and AI context.

Need to move your repository from GitHub to GitLab without losing a single commit, tag, or issue thread? This guide delivers a concise, no‑panic checklist and the exact commands you can paste into a terminal right now. Follow the steps and your migration will retain full git history, LFS objects, and discussion data—no surprises.

Why a Simple Clone Fails

A regular git clone copies only the default branch and leaves the remote‑origin pointing to GitHub. That omission means hidden refs, tags, and the reflog stay behind, causing CI pipelines to break and LFS objects to disappear. Moreover, GitHub‑only artifacts such as issues and pull‑request discussions never appear in the new project unless you explicitly import them.

The Complete Migration Checklist

  1. Create an empty project on GitLab – do not initialize it with a README or .gitignore.

  2. Mirror‑clone the GitHub repo to capture every ref:

    git clone --mirror https://github.com/youruser/yourrepo.git
    cd yourrepo.git
    

    The --mirror flag ensures tags, branches, and even the reflog are copied.

  3. Add the GitLab remote and push everything:

    git remote set-url --push origin https://gitlab.com/yourgroup/yourrepo.git
    git push --mirror
    

    This step preserves git history during migration—all commits, tags, and notes land in the new place.

  4. Migrate LFS objects (if you used Git LFS on GitHub):

    git lfs fetch --all
    git lfs push --all origin
    

    Skipping this hidden gotcha will cause CI jobs to fail.

  5. Configure protected branches on GitLab to match your GitHub settings. Navigate to Settings → Repository → Protected branches and protect main, dev, etc.

  6. Import issues and pull requests. Use GitLab’s import API or a quick curl command:

    curl -H "PRIVATE-TOKEN: <your_token>" \
         -X POST "https://gitlab.com/api/v4/projects/:id/import/github" \
         -d "repo_url=https://github.com/youruser/yourrepo"
    

    This command moves issues and pull requests from GitHub to GitLab automatically. If you prefer a manual route, export issues as JSON from GitHub and import them via GitLab’s UI.

  7. Verify the migration – clone the new GitLab repo fresh and run git log --oneline to confirm the commit history. Open a few issues and merge‑request threads to ensure they arrived correctly.

  8. Update CI configuration – copy your .gitlab-ci.yml into the repo (if it isn’t there) and trigger a pipeline manually to verify everything runs smoothly.

Post‑Migration Verification

After the push, run git remote -v to make sure no stray SSH keys still point to the old GitHub remote. A quick git fetch --all from the GitLab repo confirms that all references are present. Finally, run a test pipeline; a green status means the migration succeeded without hidden failures.

Final Thoughts

With this eight‑step process, you can migrate a repo from GitHub to GitLab without losing any history, LFS data, or discussion threads. Your team can stop worrying about “Did we lose something?” and get back to shipping code.

If you found this checklist useful, subscribe to the Dev Hacks Hub newsletter for more low‑key dev guides, or share this post with a teammate stuck in the same spot. Happy migrating!

Reactions
Do you have any feedback or ideas on how we can improve this page?