Aaron Holbrook
I'm Aaron Holbrook: a web engineer, father, gamer and geek.
Screen Shot 2015-02-19 at 1.54.38 PM

Git Subtrees – A Primer

Problem

Difficult to modularize code and maintain separate repos. Submodules are difficult or problematic to use.

Solution

Git Subtrees allow you to track and update a repo within a repo without the headache of submodules.

For a more in depth read on what / why – check out Vinicius’ awesome article.

Setup

1. Add remote to repo:
git remote add my-subtree [email protected]:account/project.git

2. Add subtree
git subtree add –prefix=path/to-repo repo-name branch

Pushing back to subtree’s repo:
1. git subtree push –prefix=path/to-repo repo-name branch

Pulling changes from subtree’s repo back to main repo:
1. git subtree pull –prefix=path/to-repo repo-name branch

Reference: https:[email protected]/git-subtrees-a-tutorial-6ff568381844