简体   繁体   中英

How to completely remove unwanted branches and commits from Git repo

I have git repo with multiple applications inside(i know is a bad idea) and now I whant to create a new repo with single branch with commits only related to this single branch.

I whant to get smaller history, smaller repo size in MB on file system. Total number of branches in 3K.

How to get this?

All you have to do here is initialize a new git repository in a new location:

$ git init

And then on your existing repository, just push your branch to the new repository:

$ git push /c/your/new/repo/root your-branch-to-push

At that point git will dump the branch from the existing repository into the new (empty) repository.

Once you complete this (and verify the new repository), take whatever action on the source branch (ie if you don't need it on the original/source repo then delete it).

In the new repository, if you want to make the pushed branch renamed to master , for instance, you can rename it like this:

$ git branch -m your-old-branch-name master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM