Git Workflow Skill
Helps you follow clean, consistent Git practices for everyday development tasks.
When to Use
- Starting new work (branch creation)
- Committing code with a meaningful message
- Preparing a pull request
- Resolving merge conflicts
- Tagging a release
- Undoing or reverting mistakes
Procedures
1. Create a Feature Branch
Follow the naming convention: <type>/<short-description>.
| Type | Use for |
|---|---|
feat |
New feature |
fix |
Bug fix |
chore |
Tooling, config, non-code work |
docs |
Documentation only |
refactor |
Code cleanup, no behavior change |
# Always branch from the latest main
git checkout main
git pull origin main
git checkout -b feat/user-login
2. Write a Good Commit Message
Use the Conventional Commits format:
<type>(<scope>): <short summary>
[Optional body: why, not what]
[Optional footer: BREAKING CHANGE, closes #issue]
Examples:
feat(auth): add JWT login endpoint
fix(cart): prevent double-charge on retry
docs(readme): update setup instructions
Rules:
- Summary ≤ 72 characters
- Use imperative mood ("add", not "added")
- Reference issues when relevant:
Closes #42
3. Pre-Pull-Request Checklist
Before opening a PR, run through this checklist:
- Branch is up to date with
main(git rebase main) - All tests pass locally
- No debug logs or commented-out code left in
- Commit history is clean (squash WIP commits)
- PR description explains why, not just what
4. Squash WIP Commits
Clean up messy history before merging:
# Interactive rebase — squash last N commits
git rebase -i HEAD~3
# In the editor: change 'pick' to 'squash' (s) for commits to merge
5. Handle a Merge Conflict
git checkout main
git pull origin main
git checkout your-branch
git rebase main # Conflicts surface here
# Fix each conflicted file, then:
git add <resolved-file>
git rebase --continue
6. Tag a Release
# Semantic version: MAJOR.MINOR.PATCH
git tag -a v1.2.0 -m "Release v1.2.0: add user dashboard"
git push origin v1.2.0
7. Undo / Revert
| Goal | Command |
|---|---|
| Undo last commit (keep changes) | git reset --soft HEAD~1 |
| Discard last commit entirely | git reset --hard HEAD~1 |
| Revert a pushed commit safely | git revert <commit-hash> |
| Discard all local unstaged changes | git restore . |
Safe rule: Use
reverton pushed commits; useresetonly on local commits.