How to rewrite the master branch history to other Repository master branch

551 views Asked by At

Is there any way or any tool or commands to re write the history of master or some A branch from some commit number to newly created master branch of NEW REPOSITORY with master branch with 0 commits or no history.

In such a way that :

  1. All the previous commits before commit number "45678" should be re written as single commit in the new repository master branch
  2. Rewriting the history should begin from commit "45678"

Thanks

1

There are 1 answers

4
Richard On BEST ANSWER

(I don't have a suitable sacrificial repository to test this: you've been warned).

I would think merge --squash could do this.

  • Add new repository as remote
  • Create dest branch, push branch with upstream tracking to the new repository
  • Checkout the new branch
  • Merge --squash from your source branch
  • Commit
  • Push to the new repository

(See this answer as well.)

Old Content (before question edit)

Just create the new repository as a new remote on your clone of the original repository; and then push to the new repository.

git remote add newrep url-to-new-repository
git push -u newrep master

Repeat the last command for each branch you want to push.