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:
- Keep all variables if they serve different purposes
- Ensure DATABASE_URL points to the correct database
- 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:
-
Remove all
__pycache__directories:find . -type d -name __pycache__ -exec rm -rf {} + -
Add to
.gitignoreif not already there:__pycache__/ *.py[cod] *$py.class *.so .Python -
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:
- Virtual environments can be hundreds of MB
- They’re platform-specific and can’t be shared between machines
- They should always be recreated locally from
requirements.txt
Resolution:
-
Remove the virtual environment from tracking:
git rm -r --cached .venv # or: git rm -r --cached venv -
Update
.gitignore:venv/ .venv/ env/ ENV/ virtualenv/ -
Commit the changes:
git commit -m "Remove virtual environment from tracking" -
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