/skills-change-commit-history

My copy of the skills course on changing commit history

MIT LicenseMIT

Remove commit history

Accidental commits can be tricky to remove with Git. In this GitHub Skills course, you'll use BFG Repo-Cleaner to change the history of a Git repository. You can apply what you learn in this course to fully remove sensitive material from your own repository.

Step 1: Removing sensitive data

Welcome to "Change commit history"! 👋

We'll start by working with .env files. These files usually contain sensitive content. For this course, we'll work on removing that file and all traces in the Git history. The first step is to remove the file from repository. We'll alter the history later.

We'll assume you're using the command line, but you can complete the course using your preferred tooling.

What is sensitive content? Sensitive content is anything that is checked into your repository history that may put you or your organization at risk. This content usually comes in the form of credentials (i.e., passwords, access keys). The best practice for accidentally exposed sensitive content is to invalidate it (i.e., revoke a personal access token), completely remove it from all repository copies, and take measures to prevent future exposure.

See Deleting a file on GitHub Docs if you need additional help removing a file.

⌨️ Activity: Remove .env in the project root directory

  1. Open your terminal of choice, clone this repository, and switch to your repository directory.
    git clone <your-repository-url>
    cd <your-repository-name>
  2. Delete .env from the root directory.
    git rm .env
  3. Commit the removal of .env.
    git commit -m "remove .env file"
  4. Push the removal to GitHub:
    git push
  5. Wait about 20 seconds then refresh this page (the one you're following instructions from). GitHub Actions will automatically update to the next step.

Get help: Post in our discussion boardReview the GitHub status page

© 2024 GitHub • Code of ConductMIT License