Git Version Control

What is Git?

Git is a distributed version control system designed to track changes in source code during software development. It’s essential for projects like Quartz Blog Setup and Web Development Basics.

Essential Commands

# Initialize a repository
git init
 
# Stage and commit
git add .
git commit -m "feat: add new feature"
 
# Branch management
git checkout -b feature/new-thing
git merge feature/new-thing
 
# Remote operations
git remote add origin <url>
git push -u origin main
git pull origin main

Git Workflow

graph LR
    A[Working Directory] -->|git add| B[Staging Area]
    B -->|git commit| C[Local Repository]
    C -->|git push| D[Remote Repository]
    D -->|git pull| A

Commit Message Convention

Conventional Commits

Use a consistent format for commit messages:

PrefixPurposeExample
feat:New featurefeat: add user auth
fix:Bug fixfix: resolve login error
docs:Documentationdocs: update README
refactor:Code restructuringrefactor: extract utils
test:Adding teststest: add unit tests
chore:Maintenancechore: update deps

Branching Strategies

Git Flow vs GitHub Flow

Choose based on your team size and release cycle.

Git Flow (for projects with scheduled releases):

  • main — production code
  • develop — integration branch
  • feature/* — new features
  • release/* — release preparation
  • hotfix/* — urgent fixes

GitHub Flow (for continuous deployment):

  • main — always deployable
  • feature/* — all changes in branches

Useful Aliases

# Add to ~/.gitconfig
[alias]
    st = status
    co = checkout
    br = branch
    cm = commit -m
    lg = log --oneline --graph --all
    last = log -1 HEAD
    unstage = reset HEAD --

Common Mistakes

  1. Committing too early — stage related changes together
  2. Poor commit messages — be descriptive, see How I Take Notes for communication tips
  3. Force pushing to shared branches — always use --force-with-lease

.gitignore

# Dependencies
node_modules/
venv/
 
# Build output
dist/
build/
 
# IDE
.vscode/
.idea/
 
# OS files
.DS_Store
Thumbs.db
 
# Secrets
.env
*.pem

Never Commit Secrets

If you accidentally commit credentials, rotate them immediately. Use environment variables and tools like Docker secrets for sensitive data.

Collaboration Tips

Best Practices

  • Pull before pushing
  • Write meaningful commit messages
  • Review diffs before committing
  • Use interactive rebase to clean up history
  • Set up pre-commit hooks

See Also


*Tags: git version-control collaboration cli