git/list[1] front-page[2] threads[3] people[4] search[5] about
 

How to properly use git-subtree (and prevent it from adding merge commits)?

From
MRManuel Reimer <mail+git@m-reimer.de>
Date
May 27, 2022, 14:54 UTC
Message-ID
<3DEED6A1-6344-472C-9E03-39ADF3076B2D@m-reimer.de>
Hello,
maybe it's a bug in later GIT versions (2.36.1 here) but I kind of struggle to get git-subtree to work properly.
I even recreated the repo, I use for the subtree, from scratch to get sure there are no backreferences to the repo I've added the subtree to.
This is the repo, I want to have as "subtree" in other repos:
https://github.com/M-Reimer/webext-utils
I now pulled this into two projects as subtree using the command

https://github.com/M-Reimer/undoclosetab https://github.com/M-Reimer/savescreenshot

For both projects I used the command:
git subtree add --prefix utils git@github.com:M-Reimer/webext-utils.git master
In the first project (undoclosetab) I then added a new commit ("Add managed preference support") and pushed this back to the "subtree repo" using:
git subtree push --prefix utils git@github.com:M-Reimer/webext-utils.git master
If I now try to pull this into my second project (savescreenshot), then git creates a merge commit for no reason.
git subtree pull --prefix utils "git@github.com:M-Reimer/webext-utils.git" master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
Unpacking objects: 100% (3/3), 1.94 KiB | 497.00 KiB/s, done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
From github.com:M-Reimer/webext-utils
 * branch            master     -> FETCH_HEAD
Merge made by the 'ort' strategy.
 utils/storage.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)
Why does this happen? As soon as I have this merge commit a following "subtree push" also pushes this merge commit to the subtree repo and also pushes tags that are not relevant there.
I'm out of ideas now.
What I want to do: I want to be able to develop on modules, I have in the "subtree repo" in every project I want and then push the changes to the subtree repo for pulling into the other projects. That's why I don't want to use "squash" as I don't want to do development only in the subtree repo directly.
Thanks for any hints.
Manuel
Next: Manuel Reimer
Message 1 of 2 in “How to properly use git-subtree (and prevent it from adding merge commits)?”
  1. Manuel ReimerMay 27, 2022
  2. Manuel ReimerMay 27, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.