Git Topic
Basic Git Workflow - Add, Commit, Status
What You'll Learn:
-
The three-stage Git architecture
-
How to effectively use git add and commit
-
Monitoring project status
Detailed Explanation:
The Three Trees of Git
-
Working Directory - Your actual files
-
Staging Area (Index) - Prepared changes
-
Repository (History) - Committed snapshots
Step-by-Step Workflow
1. Check Current Status
git status
# Shows:
# - Untracked files (new files)
# - Modified files (changed files)
# - Staged files (ready to commit)
2. Stage Changes
# Different ways to add files:
git add filename.txt # Specific file
git add src/ # Directory
git add *.js # Pattern matching
git add . # All changes
git add -A # All changes (including deletions)
# Interactive staging
git add -p # Review changes piece by piece
3. Review Staged Changes
git status # See what's staged
git diff --staged # See exact changes that will be committed
4. Commit Changes
# Basic commit
git commit -m "Descriptive commit message"
# Good commit message structure:
# Short summary (50 chars or less)
#
# More detailed explanation if needed
# - What changed
# - Why it changed
# - Any relevant context
# Examples:
git commit -m "Fix user login validation"
git commit -m "Add user profile page component"
5. View Results
git log --oneline # Compact history view
git show # Latest commit details
Common Workflow Patterns
Quick Feature Implementation:
# Make changes to files...
git add .
git commit -m "Implement user authentication"
git log -1 # Show last commit
Partial Staging:
# When you have multiple changes but want separate commits
git add file1.txt # Only stage specific files
git commit -m "Add feature A"
git add file2.txt
git commit -m "Add feature B"
Best Practices
-
Commit often, in logical chunks
-
Write clear, descriptive commit messages
-
Review changes before committing
-
Use
git statusfrequently
Comments (0)
No comments yet. Be the first to comment!