Like choosing the right vehicle for a journey, different team sizes and projects need different Git workflows.
| Factor | Centralized | GitHub Flow | Git Flow | GitLab Flow |
|---|---|---|---|---|
| Release Frequency | Continuous | Continuous | Scheduled | Variable |
| Testing Strategy | Basic | CI/CD Required | Multiple Stages | Environment-based |
| Hotfix Process | Direct to main | PR from main | Dedicated branch | Cherry-pick |
| Learning Curve | ⭐ | ⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
Git Flow is like a well-organized factory with different production lines for different purposes.
# Starting a new feature git checkout develop git checkout -b feature/payment-gateway # Starting a release git checkout -b release/1.2.0 develop # Only bug fixes allowed here! # Emergency hotfix git checkout -b hotfix/critical-bug main # Fix issue git checkout main git merge --no-ff hotfix/critical-bug git tag -a v1.1.1 -m "Hotfix version 1.1.1" git checkout develop git merge --no-ff hotfix/critical-bug
GitHub Flow is like a highway with one main road and many on-ramps - simple but effective.
Signing commits is like putting a wax seal on a letter - it proves it really came from you.
# Generate GPG key gpg --full-generate-key # List your keys gpg --list-secret-keys --keyid-format=long sec rsa4096/ABC123DEF456 2024-01-01 [SC] # Tell Git about your key git config --global user.signingkey ABC123DEF456 # Always sign commits git config --global commit.gpgsign true # Export public key for GitHub gpg --armor --export ABC123DEF456 # Copy output and add to GitHub settings # Verify signed commits git log --show-signature
Aliases are like keyboard shortcuts for your most common Git commands - save time and reduce typos!
# Quick status git config --global alias.s "status -sb" # Beautiful log git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" # Quick commit with message git config --global alias.cm "commit -m" # Amend last commit git config --global alias.amend "commit --amend --no-edit" # Unstage files git config --global alias.unstage "reset HEAD --" # Last commit info git config --global alias.last "log -1 HEAD --stat" # List all branches with last commit git config --global alias.branches "branch -av --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'" # Interactive rebase shortcut git config --global alias.rebase-i "rebase -i" # Find deleted file git config --global alias.find "!git ls-files | grep -i" # Cleanup merged branches git config --global alias.cleanup "!git branch --merged | grep -v '\\*\\|main\\|develop' | xargs -n 1 git branch -d"
git s # Quick status git lg # Beautiful graph log git cm "Add feature" # Quick commit git cleanup # Remove merged branches
Code reviews are like having a co-pilot - they catch issues you might miss and help everyone learn.
Continuous Integration and Deployment turns your repository into an automated factory that builds, tests, and ships code.
name: Complete CI/CD Pipeline on: push: branches: [main, develop] pull_request: branches: [main] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node uses: actions/setup-node@v2 with: node-version: '18' cache: 'npm' - name: Install & Test run: | npm ci npm run lint npm run test:coverage npm run build - name: Security Audit run: npm audit --audit-level=moderate deploy: needs: test if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Deploy to Production run: echo "Deploying to production..."
( ):
| Type | Pattern | Example |
|---|---|---|
| Feature | feature/[ticket-id]-description | feature/JIRA-123-user-profile |
| Bugfix | bugfix/[ticket-id]-description | bugfix/JIRA-456-cart-total |
| Hotfix | hotfix/[version]-description | hotfix/1.2.1-security-patch |
| Release | release/[version] | release/2.0.0 |
# .gitignore essentials .env .env.local .env.*.local *.key *.pem *.cert config/secrets.yml .aws/credentials # Use git-secrets to prevent commits brew install git-secrets git secrets --install git secrets --register-aws # Prevent AWS keys # Use environment variables instead export API_KEY="your-key-here" # Access in code: process.env.API_KEY
Solution:
# Choose one version
git checkout --ours path/to/file.jpg # Keep your version
git checkout --theirs path/to/file.jpg # Keep their version
# Or use Git LFS for large binary files
git lfs track "*.psd"
git add .gitattributes
Solution:
# Create a branch to save your work
git branch temp-work
git checkout temp-work
# Or return to a branch
git checkout main
Solution:
# Option 1: Rebase (cleaner history)
git pull --rebase origin main
git push
# Option 2: Merge (preserves timeline)
git pull origin main
git push
# Find who broke it git blame -L 10,20 file.js # Who wrote lines 10-20 # Search through history git log -S "function_name" # Find when function was added/removed # Clean up working directory git clean -fd # Remove untracked files and directories # Export changes as patches git format-patch -3 # Create patches for last 3 commits # Apply patches git apply patch-file.patch # Interactive add (stage parts of files) git add -p # Choose which changes to stage # Show word-level diff git diff --word-diff # List files changed between commits git diff --name-only HEAD~5 HEAD # Archive project git archive --format=zip HEAD > project.zip
You've learned everything from basic commits to advanced team workflows!
"With great Git power comes great responsibility. Use your skills wisely, commit often, and always help others on their journey!"
Commit Early • Commit Often • Push Regularly • Pull Frequently