# 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. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/cybersecurity/git
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/cybersecurity/linux-cli)

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

- [Pro Git](https://git-scm.com/book/en/v2) (git-scm.com)
- [GitHub secret scanning](https://docs.github.com/en/code-security/secret-scanning) (GitHub)
- [Gitleaks](https://github.com/gitleaks/gitleaks) (Gitleaks)

Previous: [Automating Security Tasks and APIs](https://www.internhack.in/roadmaps/tracks/cybersecurity/security-automation) · Next: [Symmetric and Asymmetric Encryption](https://www.internhack.in/roadmaps/tracks/cybersecurity/crypto-fundamentals)

## More in Scripting and Automation

- [Python for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/python-basics)
- [Bash Scripting for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/bash-scripting)
- [PowerShell for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/powershell)
- [Automating Security Tasks and APIs](https://www.internhack.in/roadmaps/tracks/cybersecurity/security-automation)
- [Git and GitHub for Security Work](https://www.internhack.in/roadmaps/tracks/cybersecurity/git)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cybersecurity Roadmap](https://www.internhack.in/roadmaps/tracks/cybersecurity)
