Accidental commits can be tricky to remove with Git. In this GitHub Skills course, you'll use BFG Repo-Cleaner to 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.
Nice work removing the file from entire history of the repository! ✨
The steps we've taken so far ensure that any new clones of the repository don't contain the sensitive data. But what about collaborators that may already have a copy of the repository? You should ask anyone with a copy of the repository to delete it and clone the repository fresh. In a real-life scenario, you'd also take additional steps to ensure no sensitive data is cached on GitHub.com.
Now that we've mitigated the risk of exposing sensitive content, we'll be proactive and prevent its addition.
We'll now configure Git so it ignores a future addition of sensitive content by adding .env
to .gitignore
. If someone should that file to the local copy of their repository, it will remain only on the contributor's machine and won't be pushed to GitHub.
What is .gitignore
? This special file allows us to tell Git naming patterns to ignore. You can read more about it in Ignoring files on GitHub Docs.
- Update the local copy of your repository to ensure you have the most recent version of the course files.
git pull
- Locate the file we added to the repository titled
.gitignore
. - Add
.env
to the file. - Stage, commit the file:
git add .gitignore git commit -m "ignore .env files"
- Push the file to GitHub.com
git push
- 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 board • Review the GitHub status page
© 2024 GitHub • Code of Conduct • MIT License