I have a project where I was originally using submodules for some dependent code. It turns out that submodules are not really appropriate for this project (and they are hard to
(Caveat: I've never worked with subtrees and I don't know how complicated your actual repo is, so these solutions may not actually work for you.)
From playing around with your sample repo, I've found two solutions that both seems to work, though they produce different commit trees:
Use git merge -s resolve origin/branch
~/q14224966[master]> git reset --hard origin/master
HEAD is now at a231acd add submodule
~/q14224966[master]> touch other.c && git add . && git commit -m "New commit."
[master bc771ac] New commit.
0 files changed
create mode 100644 other.c
~/q14224966[master]> git merge -s resolve origin/branch
Trying really trivial in-index merge...
error: Merge requires file-level merging
Nope.
Trying simple merge.
Simple merge failed, trying Automatic merge.
Adding sub/Makefile
Adding sub/README
Adding sub/src/main.c
Merge made by the 'resolve' strategy.
.gitmodules | 3 ---
sub | 1 -
sub/Makefile | 1 +
sub/README | 1 +
sub/src/main.c | 1 +
5 files changed, 3 insertions(+), 4 deletions(-)
delete mode 160000 sub
create mode 100644 sub/Makefile
create mode 100644 sub/README
create mode 100644 sub/src/main.c
~/q14224966[master]> ls
README main.c other.c sub/
~/q14224966[master]> cd sub/
~/q14224966/sub[master]> ls
Makefile README src/
~/q14224966/sub[master]> git status
# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.
#
nothing to commit (working directory clean)
~/q14224966/sub[master]> cd ..
~/q14224966[master]> git status
# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.
#
nothing to commit (working directory clean)
Here's the resulting commit tree:
Use a rebase instead of a merge:
~/q14224966[master]> git reset --hard origin/master
HEAD is now at a231acd add submodule
~/q14224966[master]> touch other.c && git add . && git commit -m "New commit."
[master ae66060] New commit.
0 files changed
create mode 100644 other.c
~/q14224966[master]> git rebase origin/branch
First, rewinding head to replay your work on top of it...
Applying: New commit.
~/q14224966[master]> ls
README main.c other.c sub/
~/q14224966[master]> cd sub/
~/q14224966/sub[master]> ls
Makefile README src/
~/q14224966/sub[master]> git status
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#
nothing to commit (working directory clean)
~/q14224966/sub[master]> cd ..
~/q14224966[master]> git status
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#
nothing to commit (working directory clean)
Here's the resulting commit tree: