Git and GitHub for Infrastructure Work
Use Git to version scripts, Terraform and pipeline files, collaborate through pull requests and keep secrets out of repositories.
Beginner · about 5 hours · difficulty 1/5
Learn first: Linux Command Line for Cloud Servers
Modern cloud teams treat infrastructure like software: everything lives in Git, changes go through pull requests and pipelines deploy from the main branch. You need Git before Infrastructure as Code or CI/CD make sense.
The essentials
- init, clone, add, commit, push, pull: the daily loop.
- Branches: work on a feature branch, merge through a pull request.
- diff and log: see exactly what changed and when.
- .gitignore: keep build output, .terraform folders and local state files out.
Collaboration on GitHub
- Pull requests with review before merge.
- Branch protection on main (require reviews and passing checks).
- Issues and READMEs to explain how to run your project, which recruiters read.
Secrets and Git
Never commit AWS access keys, .env files or Terraform state with passwords. Bots scan public GitHub for AWS keys within minutes and start crypto-mining on your account. If you leak a key, deactivate it in IAM immediately, then clean history. Deleting the file in a new commit is not enough.
Pitfalls
- Huge commits with messages like "changes".
- Force-pushing to a shared branch.
- Committing terraform.tfstate, which can contain secrets.
You are ready to move on when you can create a repo, work on a branch, open a pull request, merge it and explain why a leaked key in an old commit is still a risk.
Key concepts
- Commit, branch, merge
- Remotes, push and pull
- Pull requests and code review
- .gitignore
- Keeping secrets out of Git
- git-secrets / secret scanning
- Rebase vs merge
Mini project
Create a public GitHub repo called cloud-notes. Add your Linux script and CIDR plan from earlier topics, a .gitignore, and a README. Enable secret scanning and branch protection on main, then make one change through a pull request.
Check yourself
You pushed an AWS access key to a public repo and then deleted it in the next commit. Are you safe? What should you do?
Free resources
- Pro Git (free) (git-scm.com)
- GitHub Docs (GitHub)
- Git and GitHub roadmap (roadmap.sh)