greggyNapalm
greggyNapalm

Reputation: 543

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?

Upvotes: 0

Views: 45

Answers (1)

Thomas Stringer
Thomas Stringer

Reputation: 5862

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 (i.e. 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

Upvotes: 1

Related Questions