0

I tried to clean up an old project starting over, but now the .git folder keeps all history files that I don't need.

I explain everything I did:

I started working on an old repository.

After a few months I started over the project. So instead of creating a new repository, I created a new orphan branch and start making commits.

When I had the first version ready, I wanted to clean up old stuff just deleting the branches (develop/master) and renaming the new branch to the same branches (develop/master again)

Everything is fine, the code and git history only have the new code. But I see the .git folder is too big the only way is this big is because is keeping all history. (The project codebase size is only 15MB. And the .git folder size is 800MB).

How can I delete old objects. I see on the internet a lot of git commands related with prune and other names, but no one helped me.

I only want the objects related with my first commit of the starting over project.

Marc Pont
  • 988
  • 2
  • 14
  • 34
  • Branches are indeed what keep commits alive. If you delete all the branches that are keeping unwanted commits alive, then when garbage is collected, all those commits will be gone. You can see whether you've done that by saying `git log --all --oneline --graph` — does it contains only the commit chain that you want? – matt Apr 26 '21 at 07:23
  • Yes doing this command I see the commit chain I want. But I don't know, I feel that the repo is so big when I clone it I see it loads a lot of objects. When I was working with the orphan branch, I was using git clone --single-branch (cloning only the orphan branch) the repo was cloning so fast. And I see after doing this renaming branches it slowed everything. – Marc Pont Apr 26 '21 at 07:33
  • Does this answer your question? [Reduce git repository size](https://stackoverflow.com/questions/2116778/reduce-git-repository-size) – IMSoP Apr 26 '21 at 09:59
  • 1
    The (deprecated) `git filter-branch` command [documentation](https://git-scm.com/docs/git-filter-branch) has a "checklist for shrinking a repository" near the end, but the best way to do this is normally just to clone the old repo to a new one, then throw out the old one. – torek Apr 26 '21 at 11:07

0 Answers0