Git & GitHub

Git in Real Projects

25 דק׳

Repository hygiene

  • A README.md that explains setup in under five minutes.
  • A .env.example listing every variable with fake values, never real ones.
  • A .gitignore covering environments, caches, databases, uploads and logs.
  • Lock files (requirements.txt with 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

  1. main is green: all tests pass in CI.
  2. Database migrations reviewed and tested against a copy of production data.
  3. Version bumped and changelog updated.
  4. git tag -a vX.Y.Z and push the tag.
  5. Deploy, then watch logs and error tracking for 15 minutes.
  6. 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 נקודות)