Git and GitHub for Security Work

Version your scripts, detection rules and notes with Git, and learn why leaked secrets in repositories are a real attack vector.

Beginner · about 4 hours · difficulty 1/5

Learn first: Linux Command Line Essentials

Security teams now keep detection rules, infrastructure configs and tooling in Git ("detections as code"). Your portfolio will also live on GitHub. Learn the basics well.

Everyday Git

  • git init, git clone, git status, git add, git commit -m, git log.
  • Branches and merges: git switch -c feature, pull requests on GitHub.
  • .gitignore to keep secrets, virtual environments and large captures out of the repo.

The security angle

  • Leaked secrets: API keys, passwords and cloud credentials committed to public repos are scraped by bots within minutes. Removing the file in a later commit is not enough; the value stays in history. Rotate the secret immediately.
  • Secret scanning tools (GitHub secret scanning, gitleaks, trufflehog) catch them before or after commit.
  • Commit signing proves who wrote a change.
  • Reading history (git log -p) is also a recon technique on open-source targets in scope.

Pitfalls

  • Committing .env files or pcaps containing real credentials.
  • Force-pushing over shared history.

You are ready to move on when your scripts and lab notes live in a GitHub repo with a sensible README, a .gitignore, and a pre-commit secret scan.

Key concepts

  • Commits, branches and merges
  • GitHub and pull requests
  • .gitignore
  • Leaked secrets in history
  • Secret scanning (gitleaks)
  • Commit signing

Mini project

Create a GitHub repo for your security scripts, add a pre-commit hook running gitleaks, and verify it blocks a commit containing a fake API key.

Check yourself

You accidentally pushed an AWS key and deleted it in the next commit. Why is that not enough, and what must you do?

Free resources