---
title: "Merging two GitHub repositories without losing commit history"
description: "MDN merged small example repositories into a larger parent repo while keeping full commit history, using only plain git commands."
url: "https://swe.quest/articles/merging-two-github-repositories-without-losing-commit-history-7428e9ac84244059"
canonical: "https://hacks.mozilla.org/2022/08/merging-two-github-repositories-without-losing-commit-history/"
source: "Mozilla Hacks"
published: "2022-08-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 15
tags: ["version-control","developer-tools"]
---

# Merging two GitHub repositories without losing commit history

A post on [Mozilla Hacks](https://swe.quest/sources/mozilla-hacks.md), published 2022-08-29, 15 min read, How-to. Original: [https://hacks.mozilla.org/2022/08/merging-two-github-repositories-without-losing-commit-history/](https://hacks.mozilla.org/2022/08/merging-two-github-repositories-without-losing-commit-history/)

## Summary

MDN merged small example repositories into a larger parent repo while keeping full commit history, using only plain git commands. First, inside the source repo, all files move into a subdirectory matching the target layout (using zsh extendedglob negation like \`mv ^(sw-test|service-worker)\`, with hidden files moved separately so \`.git\` stays put). That change is merged, then the source is added as a remote in the target and merged with \`git merge --allow-unrelated-histories\`, resolving add/add conflicts such as README.md.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Version control](https://swe.quest/tags/version-control.md) (Engineering practices)
- [Developer tools](https://swe.quest/tags/developer-tools.md) (Engineering practices)

## Prerequisites

- Git basics
- shell commands

## Keywords

Git, GitHub, zsh, extendedglob, MDN Web Docs

## Related posts

- [WebKit on GitHub!](https://swe.quest/articles/webkit-on-github-d3587a8b64d71587.md): WebKit · 2022-08-31 · Easy · 2 min read · Version control, Open source, Browsers
  WebKit froze its Subversion tree on June 23rd and moved source control to git hosted on GitHub, citing git's distributed collaboration model, its author/committer model, cheap branch and revert operations, and the fact that most contributors already worked from git-svn mirrors.
- [Git Organized: A Better Git Flow](https://swe.quest/articles/git-organized-a-better-git-flow-7c1f2e19e2ec05be.md): Render · 2022-01-14 · Medium · 5 min read · Version control, Code review
  Commit-as-you-go branches often produce commits mixing unrelated or half-finished changes, which makes reverts risky and pull requests tedious to review.
- [Sapling: Source control that’s user-friendly and scalable](https://swe.quest/articles/sapling-source-control-that-s-user-friendly-and-scalable-ac4727ee939b435e.md): Meta Engineering · 2022-11-15 · Easy · 11 min read · Version control, Developer tools, Code review, Scaling, Open source
  Meta has open-sourced the client for Sapling, a Git-compatible source control system built over 10 years that scales to repositories with tens of millions of files, commits and branches.
- [Native Git support in Zed](https://swe.quest/articles/native-git-support-in-zed-e61d073bae5104a2.md): Zed · 2025-03-12 · Easy · 4 min read · Developer tools, Version control
  Zed v0.177 adds native Git support built around speed, Git-native semantics and keyboard-first workflows: a Git Panel for staging and restoring, cmd-enter commits with optional LLM-written messages and automatic Co-Authored-By lines, a hunk-level Diff View like \`git add -p\`, and fetch/pull/push from the command palette.
- [Optimizing Git’s Merge Machinery, #3](https://swe.quest/articles/optimizing-git-s-merge-machinery-3-2b68eed913acded5.md): Palantir · 2021-04-09 · Hard · 11 min read · Version control, Performance engineering, Algorithms, Open source
  Git's merge machinery can skip rename detection for source files whose renames cannot change the merge result: files unmodified on the unrenamed side of history, and files not needed for directory rename detection's majority rule.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
