Combine two git repositories into one with two branches

After Google-ing the whole day, I will have to ask experts to help me.

I cloned some public SVN repo that I converted to git. This repo has just one master branch, and it starts from some specific version, say 1.0.

I also have a git repo that was created independently, and that starts with the same 1.0 version. I created this because I wanted to hack some public project. I just downloaded the source code, created empty git repo, added version 1.0 and proceeded to hack on it. This repo also has just master branch.

Now, I would lie to create a third git repo, where version 1.0 would be the starting point, and it would have two branches: ‘svn’ and ‘mystuff’. I would like to keep history of both branches.

      /   \
     /     \
br. svn    br. mystuff
     |       |
   v1.1      v1.1'
   v1.2      v1.2'
   v1.3      v1.3'
    .          .
    .          .

If I had this I could easily get new revisions from SVN repo using svn2git, and easily merge them with my local “mystuff” branch. I don’t need to push to SVN repo, just fetch new revisions from it.

Can you help me make using git fun again?

  • Why git auto-resolved this conflict?
  • Git: how to revert after a merge conflict corruption
  • What is the proper way to do “Checkout with Rebase” and then push the merged files in Intellij IDEA
  • How do I separate a commit into a branch after doing several other commits?
  • How to configure Araxis merge with Git Extensions
  • GitLab unable to automerge. Merge request contains merge conflicts that must be resolved
  • git: how to auto-resolve files that contains no conflicts
  • Moving from Mercurial to Git and merging with custom changes
  • One Solution collect form web for “Combine two git repositories into one with two branches”

    The kind-of-hacky way is using git format-patch to export all the commits of a repo to a directory, git checkout the other’s repo 1.0 branch, create a new branch (git checkout -b new-branch), and then git am your previously generated patches.

    So, let’s call public your clone of the public SVN repo, and local the git repo you made by downloading the source and hacked onto.

    cd local
    mkdir ../patches
    # -o tells the output directory for the patches
    # the git log ... gives you the hash of the second commit of the repo (the first one
    # changes are already present in your 'public' repo
    git format-patch -o ../patches/ $(git log --pretty=format:%H | head -n-1 | tail -1)
    cd ../public
    git checkout -b mystuff 1.0
    # Apply patches
    git am ../patches/*
    Git Baby is a git and github fan, let's start git clone.