Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split git branch into separate repo

Tags:

git

I have the following git tree :

branch v2 =>                    / --- [lots of work] --- [new version] --- ref_d
                               /
  root --- ref_a --- ... --- ref_b (project reset)
             \
branch v1 =>  \ --- [some works] --- ref_c

As v1 and v2 are really different, two different team will maintain v1 and v2, I would like two separate branch two to different git repository as :

repo_v1 : from root to ref_c
repo_v2 : from ref_b to ref_d

How should I do this ? Thanks.

like image 559
AlexandreP Avatar asked Jun 08 '12 07:06

AlexandreP


People also ask

How do I move a git branch out into its own repository?

You can simply push a branch to a new repository. All of its history will go with it. You can then choose whether to delete the branch from the original repository.

How do I move a branch to another repo?

Push a new Git branch to a remote repoClone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.

What is a git subdirectory?

git. Git uses this special subdirectory to store all the information about the project, including the tracked files and sub-directories located within the project's directory. If we ever delete the . git subdirectory, we will lose the project's history. Next, we will change the default branch to be called main .


1 Answers

According to project setup I would rather

1) create new repo for v1

git checkout v1
git remote add v1_repo [email protected]:andrej/project-v1.git
git push v1_repo v1:master

2a) merge v2 into master branch.

git checkout master
git merge v2

2b) if you insist on making 2 new projects then you can create new project from the newly merged master:

git remote add v2_repo [email protected]:andrej/project-v2.git
git push v2_repo master

3) You can tidy up original repo by deleting v1 and v2 branches:

git checkout master
git branch -D v1
git branch -d v2

You have to use -D for force delete branch v1 here because v1 branch it was not merged.

like image 196
andrej Avatar answered Sep 21 '22 02:09

andrej