SYNOPSIS
--------
[verse]
-'git subtree' add --prefix=<prefix> <commit>
-'git subtree' merge --prefix=<prefix> <commit>
+'git subtree' add --prefix=<prefix> <repository> <refspec...>
'git subtree' pull --prefix=<prefix> <repository> <refspec...>
-'git subtree' split --prefix=<prefix> <commit...>
+'git subtree' push --prefix=<prefix> <repository> <refspec...>
+'git subtree' add --prefix=<prefix> <refspec>
+'git subtree' merge --prefix=<prefix> <refspec>
+'git subtree' split --prefix=<prefix> <refspec...>
DESCRIPTION
--------
add::
Create the <prefix> subtree by importing its contents
- from the given commit. A new commit is created
- automatically, joining the imported project's history
- with your own. With '--squash', imports only a single
- commit from the subproject, rather than its entire
- history.
+ from the given <refspec> or <repository> and remote <refspec>.
+ A new commit is created automatically, joining the imported
+ project's history with your own. With '--squash', imports
+ only a single commit from the subproject, rather than its
+ entire history.
merge::
Merge recent changes up to <commit> into the <prefix>
Exactly like 'merge', but parallels 'git pull' in that
it fetches the given commit from the specified remote
repository.
+
+push::
+ Does a 'split' (see above) using the <prefix> supplied
+ and then does a 'git push' to push the result to the
+ repository and refspec. This can be used to push your
+ subtree to different branches of the remote repository.
split::
Extract a new, synthetic project history from the
subproject's history to be part of your project anyway.
-EXAMPLES
---------
-Let's use the repository for the git source code as an example.
+EXAMPLE 1
+---------
+Let's assume that you have a local repository that you would like
+to add an external vendor library to. In this case we will add the
+git-subtree repository as a subdirectory of your already existing
+git-extensions repository in ~/git-extensions/.
+
+First we need to fetch the remote objects
+ $ cd ~/git-extensions
+ $ git fetch git://github.com/apenwarr/git-subtree.git master
+
+'master' needs to be a valid remote ref and can be a different branch
+name
+
+Now we add the vendor library with
+ $ git subtree add --prefix=git-subtree --squash FETCH_HEAD
+
+You can omit the --squash flag, but doing so will increase the number
+of commits that are incldued in your local repository.
+
+We now have a ~/git-extensions/git-subtree directory containing code
+from the master branch of git://github.com/apenwarr/git-subtree.git
+in our git-extensions repository.
+
+EXAMPLE 2
+---------
+Let's use the repository for the git source code as an example.
First, get your own copy of the git.git repository:
$ git clone git://git.kernel.org/pub/scm/git/git.git test-git
0a8f4f0^.. --onto=1130ef3 --rejoin \
--branch gitweb-latest
$ gitk gitweb-latest
- $ git push git@github.com:whatever/gitweb gitweb-latest:master
+ $ git push git@github.com:whatever/gitweb.git gitweb-latest:master
(We use '0a8f4f0^..' because that means "all the changes from
0a8f4f0 to the current version, including 0a8f4f0 itself.")
as easily:
$ git subtree pull --prefix=gitweb \
- git@github.com:whatever/gitweb gitweb-latest:master
+ git@github.com:whatever/gitweb.git master
Or, using '--squash', you can actually rewind to an earlier
version of gitweb:
git log gitweb-latest..$(git subtree split --prefix=gitweb)
+EXAMPLE 3
+---------
+Suppose you have a source directory with many files and
+subdirectories, and you want to extract the lib directory to its own
+git project. Here's a short way to do it:
+
+First, make the new repository wherever you want:
+ <go to the new location>
+ git init --bare
+
+Back in your original directory:
+ git subtree split --prefix=lib --annotate="(split)" -b split
+
+Then push the new branch onto the new empty repository:
+ git push <new-repo> split:master
+
+
AUTHOR
------