# Git Workflow

> Git workflow helper for common tasks. Use when asked to: create a feature branch, write a commit message, do a code review checklist, squash commits, handle merge conflicts, set up .gitignore, tag a release, or undo/revert changes. Triggers: "git", "commit", "branch", "merge", "rebase", "pull request", "PR", "release tag", "gitignore", "undo commit", "revert changes", "git workflow".

- Skill: `amitsharma1994/git-workflow` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add amitsharma1994/git-workflow`
- Raw SKILL.md: https://api.skillmd.com/api/skills/amitsharma1994/git-workflow/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: AmitSharma1994 (https://skillmd.com/u/amitsharma1994)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/amitsharma1994/git-workflow

---


# 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 |

```bash
# 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](./references/conventional-commits.md) 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](./references/pr-checklist.md):

- [ ] 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:

```bash
# 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

```bash
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

```bash
# 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 `revert` on pushed commits; use `reset` only on local commits.

---

## Reference Files

- [Conventional Commits Guide](./references/conventional-commits.md)
- [PR Checklist](./references/pr-checklist.md)
- [.gitignore Templates](./references/gitignore-templates.md)

