Bart Dorsey

Configuration & Accidentally Committed Files

Scenario H: Environment Configuration (.env)

Situation: Different environment variables added.

Example:

<<<<<<< HEAD
DATABASE_URL=postgresql://user:pass@localhost/mydb
REDIS_URL=redis://localhost:6379
=======
DATABASE_URL=postgresql://user:pass@localhost/testdb
JWT_SECRET=my-secret-key
>>>>>>> feature-branch

Resolution Strategy:

  1. Keep all variables if they serve different purposes
  2. Ensure DATABASE_URL points to the correct database
  3. Never commit sensitive data; use .env.example as a template

Scenario I: __pycache__ Directories Committed

Situation: Python cache files were accidentally committed and now cause conflicts.

Signs of this problem:

Untracked files:
  backend/app/__pycache__/main.cpython-39.pyc
  backend/app/api/__pycache__/users.cpython-39.pyc

Resolution:

  1. Remove all __pycache__ directories:

    find . -type d -name __pycache__ -exec rm -rf {} +
  2. Add to .gitignore if not already there:

    __pycache__/
    *.py[cod]
    *$py.class
    *.so
    .Python
  3. Remove from Git tracking:

    git rm -r --cached __pycache__
    git rm -r --cached "*.pyc"
    git commit -m "Remove Python cache files"

Scenario J: Virtual Environment Committed (.venv/venv/env)

Situation: Someone accidentally committed the entire virtual environment folder.

Why this is bad:

Resolution:

  1. Remove the virtual environment from tracking:

    git rm -r --cached .venv
    # or: git rm -r --cached venv
  2. Update .gitignore:

    venv/
    .venv/
    env/
    ENV/
    virtualenv/
  3. Commit the changes:

    git commit -m "Remove virtual environment from tracking"
  4. Tell team members to recreate their environments:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    pip install -r requirements.txt

Pre-commit Checklist

Before committing, always run:

git status       # look for files that shouldn't be there
git diff --staged  # review what you're actually committing