Git Subtree

I am a huge fan of git subtree.  This is a fairly new feature of git, so not all of the information on it is easy for me to remember how to use.  I’m going to post here how I use it.  The official README is here.

Also good information here.

Enable git subtree on Ubuntu

Git subtree is installed by default on Ubuntu 13.04 and 13.10, but it is not enabled.  To enable it:

sudo chmod +x /usr/share/doc/git/contrib/subtree/
sudo ln -s /usr/share/doc/git/contrib/subtree/ /usr/lib/git-core/git-subtree

Add a subtree

This command must be run from the git root directory.

git subtree add -P <prefix> <refspec> --squash

<prefix> = From the current location, list the path and directory name that you would like to clone into.

<refspec> = Te .git location.  For a github repo, this will be

The squash option squashes logs.  Leave it off if you want full log listings in your subtree.

Add your subtree repo to git’s references

Doing this will make pulling and pushing easier, you can just use your ref-name instead of having to go get the refspec again.

git remote add -f ref-name

Update your subtree

git fetch ref-name branch-name
git subtree pull --prefix <prefix> ref-name branch-name --squash

Push changes

git subtree push --prefix <prefix> ref-name branch-name

~ by Liz on October 25, 2013.

One Response to “Git Subtree”

  1. Thanks Liz, I used your suggestions to enable git-subtree on my Ubuntu box and it worked like a charm.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: