LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-merge-repo

Merge repository into subdirectory

TLDR

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

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
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

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

RESOURCES

Copied to clipboard
Kai