Skip to content

Commit 5f645c8

Browse files
committed
Add tutorial on removing sensitive data from GitHub
1 parent 584e2f5 commit 5f645c8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Remove Sensitive Data from GitHub
3+
date: 2025-03-10
4+
categories: [How-to, GitHub]
5+
tags: [github, git, bfg, security, sensitive-data] # TAG names should always be lowercase
6+
---
7+
8+
# Remove Sensitive Data from GitHub
9+
10+
In this tutorial we are going to be using nix-shell so we do not have to install any dependencies on our machines.
11+
12+
1. Run the below command to start a nix-shell with the needed tools.
13+
14+
```shell
15+
nix-shell -p openjdk17-bootstrap git bfg-repo-cleaner
16+
```
17+
18+
2. Once inside the nix-shell clone the repo with the `--mirror` command.
19+
20+
```shell
21+
git clone --mirror https://github.com/org/reponame.git
22+
```
23+
24+
3. Create a passwords.txt file containing all sensitive data that needs to be removed from the repository.
25+
26+
```shell
27+
nano passwords.txt
28+
```
29+
30+
4. Run the command to remove the passwords from git history.
31+
32+
```shell
33+
bfg --replace-text passwords.txt reponame.git
34+
```
35+
36+
5. cd into the repo directory and force git to push back to github.
37+
38+
```shell
39+
cd reponame.git
40+
git push --force
41+
```
42+
43+
6. cd back out of the directory and delete the repo folder and passwords.txt file. You will be left with a .bfg-report you can use to see what was changed. This can be deleted as well once done.
44+
45+
> If any sensitive data was included inside of a PR you will need to open a ticket with github asking them to remove the PR data from there end.
46+
{: .prompt-warning }
47+
48+
More information can be found here: [Removing sensitive data from a repository - GitHub Docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository)

0 commit comments

Comments
 (0)