git-merge-repo

Merge repository into subdirectory

TLDR

Merge another repository
$ git merge-repo [repo-url] [branch] [directory]
Merge repo into subdirectory
$ git merge-repo [https://github.com/owner/repo.git] main [lib/]

SYNOPSIS

git merge-repo url branch directory

DESCRIPTION

git merge-repo merges another repository into a subdirectory while preserving its full commit history. It is a thin wrapper around `git subtree add -P <directory> <repo> <branch>`, so the incoming history is grafted in rather than squashed away.Passing `.` as the directory is a special case: the repo is first added into a temporary subdirectory, then its files are moved up into the repository root (flattening it) instead of staying nested.The command is useful for incorporating external libraries, consolidating multiple repositories into a monorepo, or absorbing a project that was previously maintained separately.

PARAMETERS

URL

Repository URL to merge.
BRANCH
Branch to merge from.
DIRECTORY
Target subdirectory.
--help
Display help information.

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

CAVEATS

Part of git-extras package. Requires `git subtree` to be available. May need conflict resolution if paths collide.

HISTORY

git merge-repo is part of git-extras, providing repository consolidation functionality for monorepo creation and library incorporation.

SEE ALSO

git-merge(1), git-subtree(1), git-extras(1)

RESOURCES

Source code · Documentation