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/git-subtree.sh
sudo ln -s /usr/share/doc/git/contrib/subtree/git-subtree.sh /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 git@github.com:account-name/repo-name.git

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 git@github.com:account-name/repo-name.git

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
About these ads

~ 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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: