git-branch
สร้าง/สลับ/rename branch ตาม convention — upstream tracking และ cleanup local branches
SKILL.mdgit-branch/SKILL.md
GitHubGoal
Manage branches per convention — clear naming, correct upstream tracking, no accumulating local branches
Scope
- create (
git switch -c/branch), switch, rename (-m), upstream (-u), list/prune local - delete →
/delete-git-branch; merged cleanup →/cleanup-git-branch(this skill covers create/manage) - worktree branches →
/git-worktree
Execute
1. Choose Name
Goal: the branch name conveys scope and follows convention
- common convention:
<type>/<scope>-<short-desc>—feat/,fix/,chore/,refactor/— checkgit branch -ato see the repo's convention first - lowercase + hyphens, no spaces/special chars, short but readable
- if the repo has lint rules for branch names (CI checks) → follow them
2. Create And Switch
Goal: the new branch forks from the correct base
git switch -c <name> # from the current HEAD
git switch -c <name> origin/main # from the latest main — always fetch first
git switch <name> # switch to an existing branch
git fetch originbefore branching from a remote base — never branch from a stale local copy- confirm the starting point is correct — accidentally branching from another feature branch = a hidden dependency
3. Track And Push
Goal: upstream is set correctly and the first push is right
git push -u origin <name>the first time — setting the upstream makesgit push/git statuswork correctly/check-unpushto check branches that still have no upstream- the remote branch name matches local — never push under a different name without reason
4. Rename And Prune
Goal: fix wrong names and clear local refs
git branch -m <old> <new>— rename; if already pushed, push the new name + delete the old remote + reset upstreamgit fetch --prune— clear remote-tracking refs the remote has already deleted- merged local branches →
/cleanup-git-branch; unused ones →/delete-git-branch(dry-run first)
Rules
- always branch from the latest base —
git fetchbeforeswitch -c - renaming a pushed branch = recreate + delete the old one — notify collaborators
- never work directly on
main/master— always create a feature branch - local branches lingering > a week → review with
/cleanup-git-branch - Use /ask-me if needed
Expected Outcome
- branches follow the naming convention and track upstream correctly
- no stale local refs accumulating