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
1 answer

Git local submodules inside single remote

How to make a repository with 3 subfolders with its own commits history and push them together to a single remote? Android, iOS - repositories for native apps that can be checked and had their own histories. Flutter - flutter repo that has Android…
mkruglikov
  • 46
  • 5
0
votes
1 answer

Git subtree push returns remote unpack failed

this is my situation I added a external repo using git subtree add -P dir/ externalrepo master. From there I create a branch locally (git checkout -b newbranch) Made some changes, I committed and pushed them Now I just want to add those changes to…
Mike W
  • 1,303
  • 1
  • 21
  • 31
0
votes
0 answers

Pushing subtrees changes commit hash in remote

We have been using git subtrees for a while, and there's a recurring issue I've only now pinpointed. We split some library code out to a separate git repo, and different people tend to work on both the subtree repo (I'll call remote from now on) and…
shwick
  • 105
  • 1
  • 9
0
votes
0 answers

Maintain a reference to a subdirectory of an upstream Git repository

I would like to add a subdirectory of another repo into mine preserving history and maintaining a way to pull updates whenever they are added to upstream. Firstly, I considered using Git submodules; the problem is that submodules are full-fledged…
NiccoMlt
  • 135
  • 2
  • 12
0
votes
1 answer

How to read .git/index file for submodules

I have test folder in which I'm adding a submodule and after that I manually delete the .gitmodules file from the folder and then again want to add the submodule but facing error like 'test' already exists in the index if I have multiple submodules…
Puneet
  • 119
  • 1
  • 2
  • 8
0
votes
1 answer

How to create different github repos if I have one large folder with many files in it

I have a folder called coursework on my machine with many files like: file 1, file 2, file 3, file 4, file 5, and file 6. On Github, I want to create repo1 with ONLY file 1, file 2 and file 3. Also, I want to create repo 2 with ONLY files file 4,…
Harman
  • 158
  • 1
  • 9
0
votes
1 answer

Git push to main project repo throws an error after git subtree add

Trying to use git subtree to share common library files across multiple projects. Here's the problem I keep encountering. 1) Add subtree so "jquery_treetable" subdirectory of my project. $ git subtree add -P jquery_treetable…
Govardhan Reddy
  • 115
  • 1
  • 11
0
votes
0 answers

Git public subrepository

I have a private git repository in which I have my own project and some 3rd party projects. This is its rough structure: Root |- My Project | |-- myproject | |-- __init__.py | |-- __main__.py | |-- tests | |-- setup.py |- Project1 |-…
Mate de Vita
  • 1,102
  • 12
  • 32
0
votes
0 answers

How do I stop Git subtree from automatically merging conflicts?

So, I have a submodule that I'm trying to convert into a subtree. Disclaimer: I'm new to using subtrees. During my testing, I made a change in a file (changed 'foo' to 'bar') and pushed it via the subtree. Seemed to work. Then I went to the remote…
Sarov
  • 545
  • 6
  • 17
0
votes
2 answers

How do I push an ignored subdirectory to another remote?

I have two repositories. In the first, I have application code and a .gitignore containing the pattern: dist. I need to push that dist folder to the master branch of the second repository. Currently, I remove dist from the .gitignore, delete the…
Smbat Poghosyan
  • 719
  • 7
  • 20
0
votes
1 answer

Is git subtree compatible with Gerrit?

Our git repositories are hosted in Gerrit. A colleague maintains 2 repos main and sub. He wants to include sub inside main as a subtree. Here's so far what we have tried: git clone repo_url_main -b dev main cd main git subtree add -P foo/bar…
ElpieKay
  • 27,194
  • 6
  • 32
  • 53
0
votes
1 answer

How to properly update git subtree

Let's say I have a repositiory Repo and now I want to add folder Common which is separate repository. So the structure should be as following: Repo myfile.txt Common anotherfile.txt As I know there are at least 2 ways to do that:…
folibis
  • 12,048
  • 6
  • 54
  • 97
0
votes
1 answer

Missing commits when using 'git subtree split'

I had a task which is about extracting a folder from a repo and create a repo with the history of the folder extracted. I've searched the internet and I found people talking about git subtree and I used it as follows : git subtree split -P…
Alaa Agwa
  • 162
  • 1
  • 12
0
votes
2 answers

How to deploy a subfolder in repository to Heroku via Travis CI?

I have a project repository containing 2 folders: server1 and server2. I want to deploy the contents of server1 to heroku automatically as I commit them to my github repository. I do not have a CI set up currently, but am looking for Travis specific…
Kaustubh Badrike
  • 580
  • 2
  • 15
0
votes
1 answer

How can I make a copy of a sub-folder into a separate repository in Git?

I have the following repository foo.git with the following sub-folders. /foo ----/bar1 ----/bar2 I want to create a new separate repository bar1.git along with its commit history, with two copies of the contents now - at bar1.git and…
heethesh
  • 351
  • 1
  • 5
  • 11