github - Merge multiple git repositories into one, keeping branches history -
i have 4 separate projects. have own git repository. , same name of branches projects.
/project/ /project/proja/ /project/proja/.git/ /project/projb/ /project/projb/.git/ /project/projc/ /project/projc/.git/ /project/projd/ /project/projd/.git/
all git repositories have same name of branches, , of course of study own master branch.
questioni merge projects 1 so:
/project/.git/ /project/proja/ /project/projb/ /project/projc/ /project/projd/
but i want maintain history of branches.
ps -> have same name of branches repo. exemple: branche name used 4 project: v6-004
detailsi tried submodule , subtree both doesn't solve issue.
i tried this.
$ mkdir new_parent_project $ cd new_parent_project $ git init # need create initial commit. essential. $ touch readme.md $ git add together readme.md $ git commit -am "initial commit"
after
# merge project proja subdirectory proja $ git remote add together -f proja http://giturl $ git merge -s ours --no-commit proja/v6-006 $ git read-tree --prefix=proja/ -u proja/v6-006 $ git commit -m "merging proja subdir: proja"
after
# merge project projb subdirectory projb $ git remote add together -f projb http://giturl $ git merge -s ours --no-commit projb/v6-006 $ git read-tree --prefix=projb/ -u projb/v6-006 $ git commit -m "merging projb subdir: projb"
but the projects merged have history of v6-006. don't have history others branches.
that solution not far tried. works if different projects have no mutual files (otherwise can hard solve conflicts)
# create new repo: git init all_projects cd all_project # create more easy understand, let's create new branch git checkout -b main # import 1st project git remote add together projecta http://projecta git fetch --all --tags git checkout mastera projecta/master git rebase mastera main # move main branch current state git branch main -f # branch main @ same state project # import 2st project git remote add together projectb http://projectb git fetch --all --tags git checkout masterb projectb/master git rebase masterb main # move main branch current state git branch main -f # branch main contains commits projecta , projectb # etc..
the result repository 1st commits project a, commits project b, if project b has commits dated before lastly commit of project a, should not problem (and history tree easier read)
edit : sorry notice not solve problem remote branches. maybe can find solution based on that question, this:
for in $(git branch -r |grep projecta|awk -f'/' '{print $2}'); git checkout $i projecta/$i git rebase $i main done
but create tree more complex because branches starts main
commit ..
git github merge git-branch git-subtree
No comments:
Post a Comment