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
15
votes
4 answers

git-subtree conflict when pulling from central repo

I have several projects that depend on the same library, for which I'd like to maintain a separate git repository to be managed with git-subtree within each project. So for example, within each project I can do: project1$ git subtree add…
user2509951
  • 195
  • 1
  • 6
14
votes
3 answers

How do I add a subtree to an existing prefix in a new clone?

I have a main repository with two subtrees in the "external/" folder. When I clone the repository, it downloads all the files, including the code that I previously pushed after the Git subtree command. I want to clone that main repository on another…
wakeful
  • 163
  • 1
  • 6
14
votes
2 answers

Difference between git filter branch and git subtree?

Was searching throw SO for an answer to this. Came across this older thread which didn't seem to give any answers. Retriggering this thread hoping someone may know! Can someone tell me the difference b/w git subtree and git filter-branch? I'll use…
14
votes
1 answer

git submodules , gitslave, git subtree or a simpler solution

We have a git repository with N folders. Repo |-Folder1 |-Folder2 |- ... |-FolderN With different collaborators we would like to share different folders. Each collaborator should have access only to his allowed subset of folders. What is the "good"…
Issam T.
  • 1,677
  • 1
  • 14
  • 32
14
votes
1 answer

git subtree merged on root of repository (w. git-flow)

We have a repository, git-flow based, where we added an external library as a subtree (using Atlassian SourceTree's git subtree) on the development branch. Project/ Library/ X/ Y/ Z/ Later we did a git flow release, merging the…
Ramon Poca
  • 1,889
  • 1
  • 10
  • 19
14
votes
1 answer

Why does Git subtree always process every commit?

I am using Git subtree to share a subfolder of my source code between projects. This is working alright, but every time I perform a git subtree push, the terminal shows an ever-growing list of commits: git subtree push --prefix=public/js/engine…
Micros
  • 5,966
  • 2
  • 28
  • 34
14
votes
1 answer

Can I use `git subtree split` to maintain a "fork" of a project's subdirectory?

In short, I want to "fork" a subdirectory of another project (not under my control) to the top-level of a new repository and make enhancements to the code in that subdirectory while preserving the ability to merge in changes from the subdirectory in…
jasonmp85
  • 6,749
  • 2
  • 25
  • 41
14
votes
1 answer

How to get a git subtree diff?

I have a repository that has mounted another repository with git subtree add -P some/path otherremote otherbranch development has gone on with some local changes, but also with a few rounds of merges done with: git fetch otherremote git subtree…
gregw
  • 2,354
  • 20
  • 21
14
votes
1 answer

How to include part of another git repository using git subtree and merge updates in both directions

I have two git repositories show below. The first is structured like a typical python project. foo_repo/ .git/ setup.py foo/ __init__.py some_code.py tests/ bar/ .git/ I would like to include the foo_repo/foo/…
kiyo
  • 1,929
  • 1
  • 18
  • 22
14
votes
3 answers

What is the difference between git subtree merge and git-subtree

I've just found git-subtree tool that some time ago became a part of main git repo https://github.com/apenwarr/git-subtree/ However I don't fully understand what functionality does this tool provide over the already existing "git read-tree" + "git…
Eugene
  • 4,197
  • 7
  • 37
  • 54
13
votes
1 answer

How do I init submodules nested in a subtree?

Apparently, adding a subtree of a repository that has submodules will break git submodule init. Here is a script which reproduces the problem: #!/bin/sh set -ex mkdir submod cd submod git init touch foo git add foo git commit -asm "This is a…
Edward Z. Yang
  • 26,325
  • 16
  • 80
  • 110
13
votes
4 answers

Git subtree and multiple directories

I have a rather large git repository that has a directory where I maintain library code. The directory contains a number of subdirectories. repo +--- lib | +--- A | +--- B ... | +--- Z Now let us assume that I want to open source…
13
votes
1 answer

git subtree push changes back to subtree project

The short of what's below: I want to push commit messages to a subtree, but only the messages that apply to that tree. How do I do this? I have two projects, Master and Slave. Slave is checked out as a subtree of Master checked out to lib/slave…
user578895
12
votes
2 answers

Why does Git subtree push take longer the more commits I have?

I've been using the git subtree extension (https://github.com/apenwarr/git-subtree) . I use "--squash" to make the log of main project clean, my steps like this: add lib into main project git subtree add -P sub/libdir --squash lib_remote master get…
Megodno
  • 121
  • 3
12
votes
1 answer

Push changes from git subtree to a branch for a pull request

How can I create local changes to a git subtree and then push those changes to a branch in the subtree's repo so that I can then create a pull request to merge the changes from that branch into the subtree's master? Assume I have two repos, project…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213