Lessons / Part 7. Python, notebooks and the tools around them
40 Git for one person
A .gitignore proven with a probe file before the first commit keeps the venv, the raw data and the outputs out of the repository.
What people usually ask
Set up Git for my project folder so I can track changes to my analysis scripts.
What comes back
git init and a first commit of everything in the folder: the virtual environment, two gigabytes of raw instrument exports, every figure ever produced, and a README with a path that only works on this one machine.
Ask this instead
Set up Git in <project folder> for one person, no remote yet, in this order:
1. Write .gitignore first: the venv folder, data/raw/, outputs/, .ipynb_checkpoints/, __pycache__/. Then prove it: create a probe file inside data/raw/, run git status, show that the probe does not appear, delete the probe.
2. Search every note and script for an absolute path such as C:\Users\<name>\... and list each line found; change each to a path relative to the project folder.
3. Set user.name and user.email with git config --global and read them back with git config --global --list.
4. Then the first commit: scripts, notebooks, README, requirements.txt, .gitignore. Message: "Initial commit".
5. Finish with git log --oneline and git status --ignored, both pasted in full, so I can see what is tracked and what is ignored.
Stop after step 1 and show me the probe result before going on.
Attach: Nothing.
Why it works: The ignore list is tested before anything is committed, so the first commit holds only the files a person wrote.
Drafted with Fable 5.1 from my notes; chosen and edited by me.