Git in Real Projects
Repository hygiene
- A
README.mdthat explains setup in under five minutes. - A
.env.examplelisting every variable with fake values, never real ones. - A
.gitignorecovering environments, caches, databases, uploads and logs. - Lock files (
requirements.txtwith pinned versions,package-lock.json) committed, so every machine installs the same versions.
Finding secrets before they leak
git grep -n -I -E "(sk_live|AKIA|-----BEGIN .*PRIVATE KEY)"
git log -p | grep -n "SECRET_KEY="
Enable GitHub secret scanning and push protection in the repository's security settings: GitHub then blocks pushes that contain known key formats.
If a secret was committed: rotate it first, then remove it from history with git filter-repo and force-push, and tell collaborators to re-clone. Rotation is the part that actually protects you.
Hooks: automatic checks before each commit
Git runs scripts in .git/hooks/. The pre-commit framework makes them shareable:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: detect-private-key
- id: end-of-file-fixer
pip install pre-commit && pre-commit install
Now every commit is checked for private keys and huge files automatically.
Large files
Git stores every version of every file forever. Do not commit videos, datasets or build output. Use Git LFS for large assets you truly need versioned, and object storage (S3, Cloudflare R2) for user uploads.
A release checklist
mainis green: all tests pass in CI.- Database migrations reviewed and tested against a copy of production data.
- Version bumped and changelog updated.
git tag -a vX.Y.Zand push the tag.- Deploy, then watch logs and error tracking for 15 minutes.
- Know your rollback: redeploy the previous tag.
Final project
Create a repository for a small project, protect main, add pre-commit hooks, make a change through a pull request with a proper description, and tag v0.1.0. You now use Git the way professional teams do.
ההתקדמות שלכם נשמרת בדפדפן הזה בלבד.
שליחה לבדיקה (10 נקודות)