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
31
votes
2 answers

git splitting repository by subfolder and retain all old branches

I have a git repo with 2 directories and multiple branches, I want to split them and create all branches `-- Big-repo |-- dir1 `-- dir2 Branches : branch1, branch2, branch3 ... What I want I want to split dir1 and dir2 as two separate…
Sridhar
  • 803
  • 1
  • 12
  • 21
30
votes
2 answers

How to remove previously added git subtree and its history

Many moons ago I added a subtree to my git repository. This subtree included several folders and files. I added the subtree instead of creating a submodule (as recommended). Now I realize I only want one of the files in the subtree and none of the…
jlconlin
  • 14,206
  • 22
  • 72
  • 105
29
votes
3 answers

Managing 3rd party sources and binaries used by code under source control

I have a large code base under source control (was subversion, now git). To compile the code and run the tests I use a set of 3rd party libraries. These libraries can be divided into few categoriesL Binaries only 3rd party sources 3rd party sources…
Xyand
  • 4,470
  • 4
  • 36
  • 63
27
votes
2 answers

Package Manager vs. Git Submodule/Subtree

Are there any reasons to use a package manager rather than git submodules/subtrees, or vice versa? The git solutions seem to be a lot more hassle than a simple package manager. Assume that the space-saving benefit of git submodules is not important.
27
votes
1 answer

Merge multiple git repositories into one, keeping branches history

I have four separate projects. They have their own git repository. and the same name of branches for all projects. /project/ /project/projA/ /project/projA/.git/ /project/projB/ /project/projB/.git/ /project/projC/ /project/projC/.git/ …
Anas ZAHOURI
  • 309
  • 1
  • 3
  • 11
26
votes
3 answers

How to push to git subtree?

I added a subtree on git which seems to be working. I went into the directory and made some changes and then pushed. I noticed these changes show up in the parent project but the repository which I used as the source hasn't been updated. I tried…
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
24
votes
5 answers

git: How to split off library from project? filter-branch, subtree?

So, I've a bigger (closed source) project, and in the context of this project created a library which could also be useful elsewhere, I think. I now want to split off the library in its own project, which could go as open source on github or…
Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
24
votes
2 answers

git-subtree pull merge conflict

So I used git-subtree to have various branches of repoB in sub-directories of repoA, like so git clone repoA cd repoA // some commits to repoA here git subtree add --prefix=src/dirA repoB branchA I did a few commits in repoA using git subtree push…
FRob
  • 3,883
  • 2
  • 27
  • 40
24
votes
2 answers

GIT Nested repositories: Composer vs. SubModules vs. Subtree vs.?

I've finally incorporated GitHub and Composer dependency management on my workflow. It's definitely a huge step forward, although I remain very confused about GIT managing the "nested" dependecies. As I'm using an awesome Wordpress Stack…
Petr Cibulka
  • 2,452
  • 4
  • 28
  • 45
24
votes
1 answer

git subtree: possible to change subtree branch/path in a forked repository?

In a repository A the folder sub is included as git subtree of the repository S - pointing to master branch. I have forked repository A into F. Now I want to do one of the following in F: change sub to use a different branch of S (ie develop…
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
23
votes
5 answers

How can I reduce the ever-increasing time to push a subtree?

I'm using Git subtree to "link" several subprojects into the main project (I'm coming from "svn:externals"). I've used it for some weeks, but the time to push changes to the subtree remote increases every commit. $ git subtree push -P platform/rtos…
ferraith
  • 899
  • 1
  • 8
  • 19
22
votes
5 answers

git subtree error "fatal: refusing to merge unrelated histories"

I'm trying to figure out how 'git subtree' works. I've followed all directions on this page, but I always get an error trying to merge the subtree project in my own repo ('Step 2'): fatal: refusing to merge unrelated histories. I've read this post,…
Matthijs
  • 501
  • 1
  • 3
  • 12
21
votes
2 answers

Convert Git submodule to subtree

How can I convert a git submodule (with a folder in the local file system as a remote) to a git subtree, preferably preserving the commit history of the submodule?
ominug
  • 1,422
  • 2
  • 12
  • 28
21
votes
2 answers

Adding git subtree from a branch

I'm trying to add a repo (called cow) to my project using git subtree add. In particular, I'd like to add the branch stable (which is not the master branch). I tried: git subtree add -P cow https://github.com/geoffryan/cow.git stable But this…
Geoff Ryan
  • 353
  • 1
  • 2
  • 7
20
votes
1 answer

Merging subtree changes - fatal: invalid path 'somefile_BASE_20704.cs'

I have three repos - names changed for clarity: SharedStuff, ProjectA and ProjectB Both of the projects are using git-subtree to maintain a local copy of SharedStuff. They both have made local changes that I'm trying to merge up centrally, test,…
Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
1
2
3
36 37