Create a new git repository from a existing local 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:

  • How can I validate a github branch name as a string parameter in jenkins parametrized job?
  • How do I delete a Git remote branch from the NetBeans IDE?
  • How to partition a git commit in two, based on same parent?
  • With git, how do I remove a local copy of a remote branch? Or at least pull without merging?
  • rebasing branch, which has own branches
  • Git: Best way to add only some parts of a file from another branch?
  • 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!

  • SSH error on push to an existing project Permission denied (publickey)
  • How to git a folder outside the repository?
  • why git stash cannot abandon the changes made just now?
  • Git checkout commit, do stuff, and go back to master
  • a basic example of the read-tree command usage
  • Git doesnt ignore some of the files
  • 3 Solutions collect form web for “Create a new git repository from a existing local branch”

    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
    

    First, copy or clone your git repository.

    Then, find out the hash of your new root commit (m51 in your diagram). Put its commit hash into the file .git/info/grafts, then run git filter-branch --all. After you have verified the successful operation, you can remove the original/* backup refs (or re-clone the repository).

    Please note that this will create new commit hashes for all commits, so you have to be careful with already published history.

    Create your new repository, then:

    $ git add remote newrepo <path to newrepo>
    $ git checkout redesign
    $ git checkout --orphan clean
    # The branch is empty, but the files from the original branch are staged for commit.
    $ git commit -m"clean"
    $ git push newrepo clean:master
    

    Note: If you want to preserve history (or don’t care), omit the creation of the “clean”

    Git Baby is a git and github fan, let's start git clone.