Article version: Enterprise Server 2.15

This version of GitHub Enterprise will be discontinued on This version of GitHub Enterprise was discontinued on 2019-10-16. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Removing files from a repository's history

To remove a large file from your repository, you must completely remove it from your local repository and from your GitHub Enterprise Server instance.

Warning: These procedures will permanently remove files from the repository on your computer and your GitHub Enterprise Server instance. If the file is important, make a local backup copy in a directory outside of the repository.

If you added a file in an earlier commit, you need to remove it from your repository history. You can remove files from your repository history using either the BFG Repo-Cleaner or the git filter-branch command. For more information, see "Removing sensitive data from a repository."

Removing a file added in the most recent unpushed commit

If the file was added with your most recent commit, and you have not pushed to your GitHub Enterprise Server instance, you can delete the file and amend the commit:

  1. Open TerminalTerminalGit Bashthe terminal.

  2. Change the current working directory to your local repository.

  3. To remove the file, enter git rm --cached:

    $ git rm --cached giant_file# Stage our giant file for removal, but leave it on disk
  4. Commit this change using --amend -CHEAD:

    $ git commit --amend -CHEAD
    # Amend the previous commit with your change
    # Simply making a new commit won't work, as you need
    # to remove the file from the unpushed history as well
  5. Push your commits to your GitHub Enterprise Server instance:

    $ git push
    # Push our rewritten, smaller commit

Ask a human

Can't find what you're looking for?

Contact us