Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new git repository from a existing local branch

Tags:

git

branch

I have a Git repository with two branches: master and redesign. The redesign branch was created from master, and master has not been touched since then:

master
...|--m50--\
            \--m51--|--m52--|--m53-- redesign

The redesign branch has evolved so much that I would like to create a new whole repository from it, taking the first commit of redesign as the initial commit of the new repository and forgetting the previous history inherited from master:

master
...|--m50--

redesign
--r1--|--r2--|--r3--

Is this possible with Git? There is a related question to this, but its goal is to use a directory, not a branch.

Thanks!

like image 563
elitalon Avatar asked Nov 27 '11 17:11

elitalon


1 Answers

You could:

  • checkout the commit you want for the "root" of your new repo
  • copy all the files to your new directory (except the .git directory)
  • check out your redesign branch
  • git format-patch master..redesign
  • move all the generated patch files somewhere handy

Then go to your new directory and:

$ git init
$ git add .           # make sure your .gitignore is in place though
$ git commit -m"..."
$ git am /path/to/patches/*.patch
like image 106
Mat Avatar answered Sep 27 '22 23:09

Mat