Skip to content

Instantly share code, notes, and snippets.

@whisk
Last active April 3, 2017 13:14
Show Gist options
  • Save whisk/72d75656032b031f9e02c990bc698bc9 to your computer and use it in GitHub Desktop.
Save whisk/72d75656032b031f9e02c990bc698bc9 to your computer and use it in GitHub Desktop.
Working with git subtrees

Init a repo:

git init .

Make initial commit - it's required to add a subtree:

echo "git repo with subtrees" > README.md
git add README.md
git commit -m "Initial commit"

Add git repo 'A' with it's history log:

git subtree add --prefix=A https://github.com/A/A.git master

Add git repo 'B' with all commits squashed to one:

git subtree add --squash --prefix=B https://github.com/B/B.git master

Now we should have:

> ls
README.md
A
B

> git status
On branch master
nothing to commit, working tree clean

Pull changes from tree's remote:

git subtree pull --prefix=A https://github.com/A/A.git master

You are all set!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment