Skip to content

Instantly share code, notes, and snippets.

@williamdodson
Last active January 4, 2016 17:59
Show Gist options
  • Save williamdodson/8657578 to your computer and use it in GitHub Desktop.
Save williamdodson/8657578 to your computer and use it in GitHub Desktop.
Git subtree instead of submodule
# Alternative to Git Submodules using Git Subtree: http://git-scm.com/book/en/Git-Tools-Subtree-Merging
# Remember to replace 'subtree-repo' with the repo name
# --prefix can be whatever you want to call your local copy
$ git remote add -f subtree-repo /path/to/subtree-repo
$ git merge --squash -s ours --no-commit subtree-repo/master
$ git read-tree --prefix=subtree-repo/ -u subtree-repo/master
$ git commit -m "Merge subtree-repo as a subtree."
# Then to update the external subtree repo:
$ git pull -s subtree subtree-repo master
@qwertie
Copy link

qwertie commented Jul 26, 2014

So far I haven't figured out how this compares/differs to "git subtree" commands. Any tips?

@williamdodson
Copy link
Author

@qwertie: Sorry I did not receive a notice for this comment. It is in fact a subtree, but instead of a local subtree it is calling a remote and pulling that down as a subtree. I find this more flexible than using Git submodules (and far less painful to manage). 😃

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