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

Is it possible to track a folder in my repo, and also track the same folder as its own repo?

I'm working with my top-level project repo, which contains one subfolder that's a combination of project code as well as some build code. I want to track this subfolder in my top-level repo, but I also need to track this subfolder as part of its own…
jasonbarone
  • 172
  • 3
  • 17
0
votes
0 answers

GIT - Moving commits to different repository

I have this specific requirement in our project infrastructure. We have a project A with git repository location as ssh://xyz.com:/A.git Due to project requirement we had to split the modules from project A (with sub-directories/modules…
Afsar
  • 15
  • 5
0
votes
2 answers

Multiple projects in git (subtrees)

I have a git repository that I use for our ansible configuration. The directory structure is this: ansible |---Site `---Roles |---Common `---other_project This is in git, and it is private as only my team needs access to this. I would…
user26582
  • 11
  • 1
  • 3
0
votes
0 answers

Git subtree workflow - Why does subtree merge/pull always result in CONFLICT?

I encountered this issue in a real project and managed to reproduce it with the minimal steps below. EDIT: This is not a duplicate question. I saw another question which involves git subtree add and that's not the case here. The scenario is: I have…
Alex R
  • 11,364
  • 15
  • 100
  • 180
0
votes
1 answer

Ignore subproject's history with git-subtree

I want to import a new "module" library into my project using subtree, but when I imported using these commands: git remote add module git@111.111.11.1:serverUrl/module.git git subtree add --prefix=libraries/module/ module master it brings into git…
GeniDeveloper
  • 361
  • 3
  • 18
0
votes
1 answer

Git Subfolder into its own Repository to Use as Submodule Elsewhere

I have a folder structure similar to: src .git Folder1 folder1file1 Common (inside this folder are commonfile1 and commonfile2) Folder2 folder2file1 Common (inside this folder are commonfile1 and…
Adam Baruh
  • 11
  • 3
0
votes
1 answer

Add 2 local locations to same Git repo

I've been googling on Git for a few hours now and I'm going nowhere, so hope you can help. I have a local path /path/to/somewhere/ And this is in sync with my remote BitBucket repo https://bitbucket.org/company/somewhere.git Now I want to add…
Exie
  • 466
  • 5
  • 16
0
votes
1 answer

Split subdirectories into separate branch

I am trying to import my SVN project into Git. I have the following directory structure in SVN: trunk -- AAA -- UUU -- PPP -- QQQ In Git, I want this to be: master branch -- AAA -- UUU PQ-branch -- PPP -- QQQ How do I achieve this…
krasbas
  • 28
  • 3
0
votes
1 answer

How to organize source control for many subprojects?

I am creating a website with web apps within it. I am now at the stage where I am using phonegap to turn the web apps into mobile apps, but for that I need to make a branch for each app which has the app's directory as the root. How do I go about…
Marty.H
  • 1,194
  • 4
  • 16
  • 29
0
votes
2 answers

How to convert monolithic project to use git subtree

I have an existing project that uses a single repository. The directory structure looks like: * MyProject * client * server * tester * documentation * deployment * graphics I would like to modify it so that client, server, and tester…
M.M
  • 138,810
  • 21
  • 208
  • 365
0
votes
1 answer

git subtree split issues after svn2git migration

I have just converted a large nested SVN repo to git using the git2svn command line tool and now have a git repo at D:\project Repo folder structure as follows: \web\projectA \web\projectB \winforms\projectD \winforms\projectE I want to extract…
Mark Perry
  • 1,705
  • 10
  • 12
0
votes
1 answer

How can you see what branch is selected with git subtree?

I have created a repository "droid_fun", one called "droid_per" and another one called "droid_common". Now, I have added a subtree from droid_fun to droid_common to the branch "master". How can I know in the future what branch I have selected? I…
Filnik
  • 352
  • 1
  • 12
  • 33
0
votes
1 answer

Git. How to make sharing directories instead of duplicating?

I have 3 git repos with similar organization and some duplicate directories between them. They are subprojects of one big project. Proj1/ .git/ feature1_lib/ feature1_app/ feature1/ <- specific to Proj1 feature2_lib/ …
LVitya
  • 528
  • 4
  • 11
0
votes
1 answer

GIT strategy in handling 30+ repositories

I'm thinking of a GIT strategy in handling different build based on a master build. In need your opinion on how to effectively manage this large scale repo / super repo. Basically I need a single repo that has a 30+ "sub" repos in it. The reason…
Wreeecks
  • 2,186
  • 1
  • 33
  • 53
0
votes
1 answer

Can I clone a git repos with subtrees and re-link the subtrees without knowledge of the original linked branch or tag?

The Problem I'm migrating a legacy CVS repo into Git, and have run into a problem with our planned strategy involving subtrees. We're developing several different products that, in some cases, share a common library that we're also developing. I'm…