Questions tagged [git-subtree]

An alternative to the git-submodule command. Merges and splits subtrees from your project into subprojects and back. git-subtree has been merged into mainline git as of 1.7.11.

Subtrees allow subprojects to be included within a subdirectory of the main project, optionally including the subproject's entire history.

For example, you could include the source code for a library as a subdirectory of your application.

Subtrees are not to be confused with submodules, which are meant for the same task. Unlike submodules, subtrees do not need any special constructions (like .gitmodule files or gitlinks) be present in your repository, and do not force end-users of your repository to do anything special or to understand how subtrees work. A subtree is just a subdirectory that can be committed to, branched, and merged along with your project in any way you want.

They are also not to be confused with using the subtree merge strategy. The main difference is that, besides merging the other project as a subdirectory, you can also extract the entire history of a subdirectory from your project and make it into a standalone project. Unlike the subtree merge strategy you can alternate back and forth between these two operations. If the standalone library gets updated, you can automatically merge the changes into your project; if you update the library inside your project, you can "split" the changes back out again and merge them back into the library project.

For example, if a library you made for one application ends up being useful elsewhere, you can extract its entire history and publish that as its own git repository, without accidentally intermingling the history of your application project.

Note that git subtree is not an official Git command, it is a script in the contrib/ directory of the Git repository of the Git project. Some distributions do install it along with the rest of Git, though.

544 questions
20
votes
1 answer

Follow renames when performing git subtree split

I have a number of subdirectories that I want to pull out into a separate repo. In order to extract these with a single command I move (rename) them to a single subdirectory inside the root. I then run: git subtree split -P my_new_subdir -b…
el_tone
  • 1,182
  • 8
  • 16
20
votes
2 answers

Git confused when merging an update into my subtree

We previously used many submodules in our main repositories, but to increase the maintainability of our projects we started an experimental branch where we replaced them all with subtrees. This worked good - but now when I'm trying to update one of…
VoxPelli
  • 2,697
  • 1
  • 16
  • 22
20
votes
1 answer

Git using subtree or submodule to manage external resources

I read much about how awful the git submodule is supposed to be, but I am not sure if that is just the groaning of people who feel it limits or if it has serious issues (especially concerning my use case). I just want to include different repos into…
Lukas Oppermann
  • 2,918
  • 6
  • 47
  • 62
19
votes
4 answers

Merge error after converting Git submodule to subtree

I have a project where I was originally using submodules for some dependent code. It turns out that submodules are not really appropriate for this project (and they are hard to use in practice), so I am converting each submodule to a subtree (using…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
18
votes
2 answers

git reports merge conflict with no changes, empty lines (using git-subtree)

I'm testing the use of git-subtree to merge a library repo into a bigger project. It seems great in principle. Sometimes when I do a "git subtree pull" I get merge conflicts like this: <<<<<<< HEAD ======= An inserted line from the lib repo >>>>>>>…
Jeremy Slade
  • 4,058
  • 1
  • 18
  • 14
18
votes
2 answers

git-subtree is not retaining history so I cannot push subtree changes, how can I fix this/avoid this issue in the future?

I've been using the git-subtree extension (https://github.com/apenwarr/git-subtree) to manage sub-projects within our main project. It's doing exactly what I want other than the fact that it fails when I try to split out changes made to a…
Screndib
  • 1,024
  • 11
  • 23
18
votes
5 answers

Best practices for using Git with Magento?

I'm working at figuring out how to best work within my own repo for custom code while integrating with a vendor's library (in this case Magento). In my case, I will not need to push up patches to the vendor (although that would be a great side…
acorncom
  • 5,975
  • 1
  • 19
  • 31
18
votes
5 answers

git subtree split "No new revisions were found"

I've been using git subtree split to divide up one huge repository, imported to Git from another VCS, into smaller repositories. $ git subtree split -P ./path/to/folder/ -b folder-only This has been working and I've moved a couple of folders out…
Boggin
  • 3,251
  • 3
  • 33
  • 48
18
votes
5 answers

When to break up a large Git repository into smaller ones?

I am working on doing a migration from SVN to Git. I have already used git-svn to get the history into a single git repository, and I already know how to use git-subtree to split that repository into smaller ones. This question is not about how to…
onionjake
  • 3,905
  • 27
  • 46
18
votes
2 answers

git-subtree without squash: view log

I merged a tree onto a my repository by using git subtree add without the squash option. A git log shows that the commits were successfully added to the repository. However, if I do a git log --follow filename, the history stops at the merge and…
Bryan Larsen
  • 9,468
  • 8
  • 56
  • 46
16
votes
3 answers

Git subtree split two directories

I've been following this excellent answer to extract a subdirectory of my git repository into its own repository, while retaining the complete history. My repository looks like: src/ http/ math/ tests/ http/ math/ I want to create a…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
16
votes
1 answer

Git subtree: Use only subrepository instead of whole repository

I have a project that uses some 3rd Party libraries. So the directory structure is something like: MY_COOL_PROJECT 3rdParty LIB_1 LIB_2 Source MY_PROJECT The libraries are located in separate repositories. So, if I want…
user2070238
  • 223
  • 5
  • 9
16
votes
2 answers

git-subtree: Push changes from an cloned repo

I'm using git-subtree(from Avery Pennarun). In my current git repo I have of course all my project files/folders and a subtree called "lib". If I now clone this git repo using git clone I get all of the project files and the subtree "lib"…
arge
  • 635
  • 1
  • 7
  • 16
15
votes
5 answers

How can I mirror a directory in a git repo into another git repo?

I have a directory /amp in RepoA and a RepoB (populated with the contents of /amp initially). I want to mirror any changes to the /amp in RepoA into RepoB. Is it possible ? P.S: RepoA contains many other directories. I only want to mirror the /amp…
mukilane
  • 302
  • 3
  • 9
15
votes
2 answers

Git - deploy dist folder to different remote

I'm trying to figure out a way to deploy a dist folder to a different remote repo using Git. The working project is stored in an app folder. I use grunt to optimize and compile the working project into a dist folder. I want to know if there is a…
pixelworlds
  • 818
  • 2
  • 11
  • 22
1 2
3
36 37