#Why this matters
As you write Python triage scripts and regex log parsers, you need a safe way to track changes, test edits on separate branches, and share code with teammates. Git handles local version history, while GitHub hosts remote repositories for collaboration and Pull Request (PR) code review.
For security engineers, Git is both a daily tool and a common source of leaks. Because Git keeps every committed snapshot, a password or API token removed in a second commit still lives inside the first commit. Worse, if a deployment copies the hidden .git folder onto a public web server, anyone can download that history.
#Core Git workflow and three areas
Git separates your work into three distinct places:
- Working tree: the files you currently see and edit in your project folder.
- Staging area (index): the exact changes you mark with
git addfor the next snapshot. - Repository history (
.git/): permanent commits stored locally, which you push to a remote like GitHub.
- Working treeedit scripts or configs
- Staging areaselect changes with git add
- Local commitrecord snapshot with git commit
- GitHub PRpush branch and request review
Working on a feature branch instead of editing main directly keeps half-finished scripts isolated and lets another engineer review your git diff before merging.
| Command | What it does |
|---|---|
git status |
Shows current branch, modified files, and staged changes |
git switch -c fix-parser |
Creates and switches to a new branch named fix-parser |
git add parser.py |
Stages parser.py for the next commit |
git diff |
Compares unstaged working tree edits against the index |
git commit -m "Add IP check" |
Records staged changes as a new commit |
git log --oneline |
Lists commits concisely with short IDs and messages |
git show <hash> |
Displays the metadata and patch for a single commit |
#Auditing history and finding buried secrets
Suppose a developer accidentally commits a test credential inside config.py, notices the mistake, deletes the line, and creates a new commit titled "Remove test key". On main, the current file looks clean. However, Git never erases the earlier snapshot when you add a new commit on top.
Using git log and git show (or git log -S to search history for commits that added or removed a specific string), an auditor can read every past line:
$ git log --oneline
b8f12c4 Remove test key
a319e02 Add initial config loader
$ git show a319e02
commit a319e02...
Author: Lab Dev <dev@example.test>
Add initial config loader
diff --git a/config.py b/config.py
new file mode 100644
--- /dev/null
+++ b/config.py
@@ -0,0 +1,2 @@
+LAB_API_URL = "http://lab.local/api"
+LAB_TOKEN = "demo_token_8472"When auditing a large repository, git log -S "LAB_TOKEN" -p jumps straight to the commits where "LAB_TOKEN" appeared or disappeared, saving you from reading hundreds of unrelated diffs.
#Exposed .git directories on web servers
Inside every repository sits a hidden .git/ directory containing HEAD (pointing to the active branch), config (remote URLs), index (tracked file list), and objects/ (compressed file blobs, trees, and commits).
In veb-tahlil labs and real-world misconfigurations, teams sometimes deploy a website by copying the entire project folder into a web server's document root without excluding .git/.
Even when directory listing is disabled, fetching known files such as /.git/HEAD confirms whether .git is accidentally exposed over HTTP.
#Defending and common mistakes
- Treating
git rmas secret erasure: Removing a secret in a new commit leaves it visible in history. If a real key or password was ever pushed, rotate (revoke) the credential first, because anyone who fetched the repository may already hold a copy. - Skipping
.gitignore: Create a.gitignorefile before your firstgit addso.envfiles, private keys (*.pem,*.key), and temporary dumps are never staged by accident. - Using
git add .blindly: Reviewgit statusandgit diffbefore staging so stray artifacts do not slip into commits. - Serving
.git/in production: Configure web servers and reverse proxies to deny all requests to/.git, or build clean deployment packages that omit.git/entirely. - Merging without review: Enable branch protection on
mainin GitHub so every change requires a Pull Request review and automated secret scanning checks.
#Summary
Git tracks code across a working tree, staging area, and immutable commit history, while GitHub adds branches and Pull Requests for peer review. Because commands like git log -p, git show, and git log -S reveal every historical snapshot, deleting a committed secret in a later commit does not hide it. Protect repositories by maintaining .gitignore, rotating leaked credentials immediately, reviewing diffs before pushing, and blocking HTTP access to .git/ on web servers.