SourceTree: Obliterating large files from a Git repository

Our git repository is around 2GB and when cloned accounts for around 3GB due to the checkout in the workspace. I know there are a couple of very large binaries that may have been deleted form version control in the past but still exist in the repository.

Is there a way using either SourceTree or Stash to identify and/or delete these files?

1 answer

1 accepted

0 votes
Accepted answer

Hmmmm ... as those files are part of the history of your project they shold not be removed from the repository - doing so you won't be able to checkout a complete historical version of your software (as the files you removed finally are not part of the repository anymore).

Usually removing files from the repository is only done when those files were added by accident and you are completly sure you don't need them - even in historical versions of your software. If you say, "I don't need the files anymore" this involves you needed the files earlier - and therefore the files should not be removed (as you cannot reconstruct them)

Removing files from the repository is a git task - and therefore not part of stash. Sourcetree does not offer this as well - you have to do this on comand-line using the command

git filter-branch --tree-filter ....

as for example described here.

The best way to do this, is cloning your repository from stash and performing the git-filter action on your local clone. After approval that your local repository looks fine, you should remove the "huge" repository from STASH and re-push the modified repository. After this you have to be sure that all of your coworkers remove their old local copies of the repository and clone the modified one!

If your main concern is the size of the repository to clone (2-3GB) you should consider to do a shallow clone (as for example described here). A shallow clone allows you to clone a repository keeping only the latest n commits of history. Therefore you can omitt those large historical files from cloning - with the drawback not to have the complete history of your project locally available.

Thanks Johannes.

Yes, the large files I would like to delete were added accidentally and are not being used at all. Thanks you for the link that explains how to go about with removing the files.

Shallow clones may not be for us as it has some limitations about committing changes to that type of clone.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Agile

Are you a Jira Service Desk agent? We want to talk to you!

Are you a whiz at handling tickets and looking at how you can further optimize your workflow with automation? Do you tackle detailed customer support questions while simultaneously getting flooded wi...

35 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you