Files
git-templates/git-quick-reference.md
2025-06-02 14:37:44 -04:00

3.0 KiB

Git Commands Quick Reference Card

Essential Daily Commands

Starting Your Work Session

git status                    # Check current repository state
git pull origin main         # Get latest changes from remote
git checkout -b feature/name  # Create and switch to new branch

During Development

git status                    # Check what files have changed
git diff                      # See what changes you've made
git add filename             # Stage specific file
git add .                    # Stage all changes
git commit -m "message"      # Save changes with description
git push origin branch-name  # Backup your work to remote

Completing a Feature

git checkout main            # Switch back to main branch
git pull origin main        # Get latest changes
git merge feature/name       # Merge your feature
git push origin main         # Push completed feature
git branch -d feature/name   # Delete local feature branch

Emergency Commands

git stash                    # Temporarily save uncommitted work
git stash pop               # Restore stashed work
git reset --soft HEAD~1     # Undo last commit, keep changes
git checkout -- filename    # Discard changes to specific file

Information Commands

git log --oneline           # View commit history
git branch -a               # See all branches
git remote -v               # See remote repositories
git diff HEAD~1             # Compare with previous commit

Commit Message Best Practices

Good Examples:

  • Add user authentication system
  • Fix login validation bug
  • Update README with installation steps
  • Refactor database connection logic

Bad Examples:

  • fixed stuff
  • updates
  • asdf
  • commit

Conventional Commit Format:

  • feat: add user registration
  • fix: resolve login timeout issue
  • docs: update API documentation
  • style: format code with prettier

File Naming Conventions

Repository Names:

  • Use lowercase letters
  • Use hyphens instead of spaces
  • Be descriptive but concise
  • Examples: user-management-system, blog-website, data-analysis-tools

Branch Names:

  • feature/add-user-auth
  • bugfix/fix-login-error
  • docs/update-readme
  • hotfix/critical-security-patch

File Names:

  • Use meaningful names
  • Follow language conventions
  • Examples: user_controller.py, LoginForm.js, database-schema.sql

Common Git Patterns

Feature Development Workflow:

main branch
    ↓
feature branch (work here)
    ↓
merge back to main
    ↓
delete feature branch

Daily Routine:

Morning:  git pull origin main
Work:     edit → add → commit → push (repeat)
Evening:  merge completed features to main

Project Structure:

my-project/
├── README.md
├── .gitignore
├── LICENSE
├── CHANGELOG.md
├── src/
│   ├── main.py
│   └── utils.py
├── docs/
│   └── setup.md
└── tests/
    └── test_main.py