About subtree merges
Typically, a subtree merge is used to contain a repository within a repository. The "subrepository" is stored in a folder of the main repository.
The best way to explain subtree merges is to show by example. We will:
- Make an empty repository called
testthat represents our project. - Merge another repository into it as a subtree called
Spoon-Knife. - The
testproject will use that subproject as if it were part of the same repository. - Fetch updates from
Spoon-Knifeinto ourtestproject.
Setting up the empty repository for a subtree merge
-
Open TerminalTerminalGit Bash.
-
Create a new directory and navigate to it.
mkdir test cd test -
Initialize a new Git repository.
$ git init > Initialized empty Git repository in /Users/octocat/tmp/test/.git/ -
Create and commit a new file.
$ touch .gitignore $ git add .gitignore $ git commit -m "initial commit" > [main (root-commit) 3146c2a] initial commit >