STAT 159: Collaborative and Reproducible Data Science
Basic Git commands:
git statusgit addgit commit -m "..."git loggit diff.gitignore file
System Level
Apply to every user of the computer
User Level
Apply to a single user
Project Level
Project to project configurations
| Command | Level |
|---|---|
git config --system |
system level |
git config --global |
user level |
git config |
project level |
This is the most common type of configuration (e.g. the one you used in lab)
Short summary of changes (50 characters or less)
git commit -m "first commit"
git commit -m "add index file"
Short summary of changes (50 characters or less)
More detailed explanatory text, if necessary. Wrap it to
about 72 characters. Focus on the "why" rather than the "how."
Use the imperative mood: e.g., "Add feature" instead of "Added feature" or "Adds feature"
Follow a specific structural logic
Good messages are searchable
They explain why a change was made without needing to decipher the code from scratch.
If a change fixes a specific bug or relates to a task ticket, developers include the ID at the end of the subject or body (e.g., fix: close database connection leaks (closes #402)
Bad example:
Many teams follow a strict prefix naming system to categorize changes. This makes the Git log easily machine-readable for automated changelogs.
feat: add user authentication login endpointfix: resolve memory leak in database connectordocs: update setup instructions in READMEstyle: correct indentation layout in dashboard filerefactor: optimize data processing loop performance[py,R]: ... (modifying python, R files)bugfix: ... (all bug fixes commits)#35890: ... (tracking numbers)Never write single-word or lazy messages like:
"fixed""update""stuff""bug fix""working""manifesto"👎 They offer zero historical value.
Example: nice commit messages
commit 9e2f41c (HEAD -> main, origin/main)
"docs: update API authentication steps in README"
commit 8d1e30b "fix(auth): resolve token expiration memory leak (#402)"
commit 7c0d29a "style: fix navigation bar alignment on mobile screens"
commit 6b9c18f "refactor(data): optimize database query processing loops"Example: nice commit messages
commit 9e2f41c (HEAD -> main, origin/main)
"docs: update API authentication steps in README"
commit 8d1e30b "fix(auth): resolve token expiration memory leak (#402)"
commit 7c0d29a "style: fix navigation bar alignment on mobile screens"
commit 6b9c18f "refactor(data): optimize database query processing loops"
commit 5a8b07e "test: add integration tests for user login validation"Example: nice commit messages
commit 9e2f41c (HEAD -> main, origin/main)
"docs: update API authentication steps in README"
commit 8d1e30b "fix(auth): resolve token expiration memory leak (#402)"
commit 7c0d29a "style: fix navigation bar alignment on mobile screens"
commit 6b9c18f "refactor(data): optimize database query processing loops"
commit 5a8b07e "test: add integration tests for user login validation"
commit 3e6d85c "feat(auth): implement user registration API endpoint"Example: nice commit messages
commit 9e2f41c (HEAD -> main, origin/main)
"docs: update API authentication steps in README"
commit 8d1e30b "fix(auth): resolve token expiration memory leak (#402)"
commit 7c0d29a "style: fix navigation bar alignment on mobile screens"
commit 6b9c18f "refactor(data): optimize database query processing loops"
commit 5a8b07e "test: add integration tests for user login validation"
commit 3e6d85c "feat(auth): implement user registration API endpoint"
commit 2d5c74b "chore: initialize project dependencies and folder structure".gitignore file.gitignore fileA .gitignore file1 is a plain text file placed in the root directory of a Git repository that explicitly tells Git which files and folders to ignore.
Keeps Repositories Clean: It prevents junk files like system logs (.log), temporary folders, and OS-generated files (like Mac’s .DS_Store) from cluttering your repository.
Secures Private Data: It blocks you from accidentally uploading sensitive credentials, API keys, passwords, or configuration files (like .env) to public platforms like GitHub.
Saves Storage Space: It keeps massive data directories, external libraries (like Node’s node_modules or Python’s venv), and heavy compiled binaries out of your Git history.
.gitignore
Warning: Git can only ignore untracked files!
If you commit a file first, and then add it to your .gitignore later, Git will continue to track it.
To fix this and force Git to honor the new rule, you have to manually remove the file from your active staging cache using the command:
git rm --cached <filename>
