2

I have a project that was created from a tar ball and put under separate version control (at the time, the upstream did not use git). Now, upstream has migrated to git as well and I would like to reconnect the custom repository with upstream.

I assume it would be possible to add it as a remote and merge branches as shown in the diagram.

The problem is that the custom repository (loosely called fork here) has a different base dir. It includes a parent folder and holds the upstream file structure in /src.

How is it possible to merge these repositories so upstream can be tracked via git, without loosing the forks commit history?

folder structure and diagram showing desired result

cjoy
  • 406
  • 5
  • 14

1 Answers1

0

In your custom repo do:

# Adapt structure to match upstream's structure
#
mkdir src
git mv repo_content.txt src
git commit -m 'adapt structure to upstream'

# Add remote to upstream repo
#
git remote add upstream git@upstream.com/repo
git fetch

# Do the merging,...
# (only master branch is considered here)
#
# Prepare to do some conflict solving, as merging without a
# common history may be a bit more "rough" when repo's
# diverted significantly.
#
git merge upstream/master
Hkoof
  • 756
  • 5
  • 14
  • The src dir is not part of the upstream structure. It is the other way around. Compared to the solution proposed in http://stackoverflow.com/questions/3212485/how-do-i-re-root-a-git-repo-to-a-parent-folder-while-preserving-history this seems surprisingly simple. I will test and report. Thanks. – cjoy Jun 16 '15 at 14:35