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

How to upload my AngularJS static site to Github Pages?

I have created a static site with AngularJS and now want to upload it as a Github Page. I have followed all the instructions here https://help.github.com/articles/creating-project-pages-manually I can create a new branch named gh-pages and git push…
user883807
12
votes
1 answer

Extract a subtree using branch incrementally

I'm using git-subtree to extract a directory from my project. git subtree split --prefix=src/SubProject --branch=SubProject origin/master Given this is how I would like to start the project to begin with (specifically no --rejoin) how can I split…
Beau Simensen
  • 4,558
  • 3
  • 38
  • 55
12
votes
1 answer

How do I go to a specific commit using git-subtree?

I am using Avery Pennarun's git-subtree which is an extension to git. How do I cherry-pick a commit from a sub-repo into my main repo using git subtree? Also how do I go to a specific commit in the history of the sub-repo after I have already done…
owagh
  • 3,428
  • 2
  • 31
  • 53
11
votes
2 answers

Why can't I push change to this up-to-date Git subtree?

I have a git subtree module called "gempak-tables" in subdirectory "gempak/tables": $ git config -l | grep -i…
Steve Emmerson
  • 7,702
  • 5
  • 33
  • 59
11
votes
1 answer

How to remove git subtree reference

I added a subtree via git subtree add --prefix=path/to/example --squash git@github.com:johndoe/example.git master and want to remove it. There's no git subtree rm command. I already deleted all files in path/to/example but path/to/example still…
ryanve
  • 50,076
  • 30
  • 102
  • 137
11
votes
1 answer

How do I install git-subtree with Cygwin in Windows 7?

I'm struggling to install git-subtree with Cygwin and there hasn't been any good tutorials online focused on building from source in Windows. Have you ever had this issue, and what is the best strategy to tackle it?
dot_zero
  • 1,030
  • 3
  • 12
  • 26
11
votes
1 answer

Managing Internal Shared Libraries with Git and Nuget

I have just started splitting up our Git repository that houses all of our product code, which includes shared libraries, server, client, and tooling code. As a part of removing some of the tech-debt we have with our DCVS, we are proposing moving…
Daniel Park
  • 3,903
  • 4
  • 23
  • 38
11
votes
3 answers

Merge changes from one repo to another with different tree structures

I have two Git repos, foo/master and bar/master: In foo: code_root ->dirA ->dirB -> *some files* In bar: code_root -> *same files as above* Now someone has made changes to *some files*... how do I get those changes merged into *same files…
RavenHursT
  • 2,336
  • 1
  • 25
  • 46
11
votes
1 answer

git subtree push and split adding "-n" to commit messages

Whenever I split a subdirectory into a branch via git subtree split or (consequently?) when I push a subtree upstream, the commit messages in the new branch/upstream commits have "-n" and a newline prepended to them. It's easiest to demonstrate with…
Bryan Head
  • 12,360
  • 5
  • 32
  • 50
11
votes
2 answers

How can I create a gitsubtree of an existing repository?

I'm trying to create a gitsubtree of an existing repository, for example: -> projectA/projectB Project A is the parent, i want to add project B as a git subtree. git subtree -P projectB ssh://git@github.com/projectB.git master But it fails, and…
ricardotk
  • 111
  • 1
  • 4
11
votes
2 answers

Is git svn compatible with git subtree?

Now that git subtree has been merged into the core git distribution (its also on Msysgit as of 1.8.0), does anyone know if git svn works with git subtree? Note: I am not talking about the subtree merge strategy, but about this. Git submodules cannot…
Carl
  • 43,122
  • 10
  • 80
  • 104
11
votes
1 answer

Make existing folder a git subtree

Following my question Git subtree export and re-import woes I wanted to ask how I would convert a folder to a subtree. Imagine I have a repository A where I have code that should now be shared with another project (and possibly more), so I put all…
Frankie
  • 653
  • 1
  • 9
  • 20
10
votes
2 answers

How can I add a specific folder when using git subtree?

I have a complicated Ionic project I'm developing. Many of the components and providers I'm developing are generic and can be used in other projects my company is doing. This is common in software development. This is the Git workflow I have come up…
juliet
  • 421
  • 3
  • 13
10
votes
1 answer

How to merge a git repository with submodules into another with subtree merge?

I have a dotfiles repository. I want to merge another one with submodules (prezto) into it, so I can conveniently have everything in one repository without the inconvenience of submodules. How can I subtree merge prezto into my dotfiles repository…
kissgyorgy
  • 2,947
  • 2
  • 32
  • 54
10
votes
1 answer

Transferring from SVN to GIT, merge workflow changes from SVN to GIT with shared repositories

Right, so I am tasked with finding out if GIT would be a solution for an upcoming problem that we are having. (Easily creating feature branches, hotfix branches, bugfix branches, while keeping the trunk clean and only feature completed issues…
Daan Timmer
  • 14,771
  • 6
  • 34
  • 66