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.
- Git fetch and merge skipped asking me for conflicts
- Git - error while merging because of local changes in master
- Pull only latest commits to shallow clone
- Teamcity fails to merge automatically
- Maintain some changes on git merge
- Git: Rebase or Merge to update a local branch
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.
1.0 / \ / \ 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?
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/*