Chapter 5 Essential Git Commands
5.1 Understanding Git Workflow
Before diving into commands, let’s understand the basic Git workflow:
Basic Workflow:
- Modify files in your working directory
- Stage changes you want to include in next commit
- Commit staged changes to repository
- Push commits to GitHub
5.2 Essential Git Commands
5.2.1 1. Starting a Repository
Option A: Clone existing repository
Option B: Initialize new repository
5.2.2 2. Check Status
Most important command - use frequently:
This shows:
- Which files are modified
- Which files are staged
- Which files are untracked
5.2.4 4. Commit Changes
Commit with message (used almost always):
Commit with detailed message (rarely used):
5.2.7 7. Undo Changes
⚠️ WARNING: These commands are for experienced users only! If you’re new to Git, please consult a more experienced Git user before venturing into this jungle. These commands can permanently delete your work if used incorrectly.
Unstage files:
Discard changes in working directory:
Undo last commit (keep changes):
⚠️ Dangerous: Undo last commit and discard changes:
5.3 Daily Research Workflow
# Start your day
git status # Check current state
git pull # Get latest changes
# Work on your files
# ... edit files ...
# Save your work
git add . # Stage all changes
git status # Review what you're committing
git commit -m "Update analysis results"
git push # Share your changesNext Chapter Preview: Now that you know the essential Git commands, you’re ready to put everything together into a complete workflow. In the next chapter, we’ll create your first GitHub repository, connect it to your local computer, and learn the three-command workflow that handles 90% of your daily Git needs.