Git Workflow Guide
Workflow types, commands, best practices, and commit messages.
Workflow Types
Feature Branch
Each feature in separate branch, merge to main
Use: Small teams, simple projects
GitFlow
Main, develop, feature, release, hotfix branches
Use: Structured releases, enterprise
Trunk Based
All work on main, short-lived branches
Use: CI/CD, continuous delivery
GitHub Flow
Main + feature branches, PR before merge
Use: GitHub projects, teams
Forking
Fork repo, changes in fork, submit PR
Use: Open source, public projects
Key Commands
git checkout -b feature
Create and switch to branch
git merge main
Merge main into current branch
git rebase main
Rebase commits onto main
git cherry-pick
Apply specific commit
git stash
Save changes temporarily
git reset --soft
Undo commit, keep changes
Best Practices
Commit often
Small, logical commits
Write good messages
Clear, descriptive commit messages
Pull before push
Sync with remote before pushing
Use branches
Never work directly on main
Review before merge
Code review via PR
Keep branches short
Merge/delete feature branches
Commit Message Format
Prefix with type: feat, fix, docs, style, refactor, test, chore
Brief summary (50 chars max)
Body explains why (wrap at 72 chars)
Reference issues: Fixes #123
Example: feat: Add user authentication
Workflow Checklist
1. Choose workflow (feature branch, GitFlow, trunk-based). 2. Create branch for changes. 3. Make small commits with good messages. 4. Push branch regularly. 5. Pull changes from main/base. 6. Resolve conflicts early. 7. Open pull request. 8. Get code review. 9. Address feedback. 10. Merge when approved. 11. Delete feature branch. Consistent workflow = team productivity.