Back to Skills

manage-git-branches

pjt222
Updated 2 days ago
11 views
17
2
17
View on GitHub
Metaai

About

This Claude Skill helps developers manage Git branches for creating features, switching contexts, and keeping branches synchronized. It handles branch operations with proper naming conventions, safe switching using stash, upstream syncing, and cleanup of merged branches. Use it when starting new work, switching between tasks, updating feature branches, or cleaning up after merges.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/manage-git-branches

Copy and paste this command in Claude Code to install this skill

Documentation

管 Git 枝

以一致命名建、換、同、清諸枝。

用時

  • 啟新特性或修疵之工
  • 於異枝之任間換
  • 保特性枝於 main 為新
  • 合併 pull request 後清枝
  • 列並察諸枝

  • 必要:至少一提交之倉
  • 可選:枝之命名慣(預設:type/description
  • 可選:新枝之基(預設:main
  • 可選:遠端之名(預設:origin

第一步:建特性之枝

用一致之命名慣:

feature/新功feature/add-weighted-mean
fix/修疵fix/null-pointer-in-parser
docs/文件docs/update-api-reference
refactor/碼重構refactor/extract-validation
chore/chore/update-dependencies
test/試加test/add-edge-case-coverage
# Create and switch to a new branch from main
git checkout -b feature/add-weighted-mean main

# Or using the newer switch command
git switch -c feature/add-weighted-mean main

**得:**新枝已建並換。git branch 現新枝於星旁。

**敗則:**若基枝本地無,先取之:git fetch origin main && git checkout -b feature/name origin/main

第二步:追遠端之枝

首推新枝時立追:

# Push and set upstream tracking
git push -u origin feature/add-weighted-mean

# Check tracking relationship
git branch -vv

取他人所建之遠端枝:

git fetch origin
git checkout feature/their-branch
# Git auto-creates a local tracking branch

**得:**本地枝追對應遠端枝。git branch -vv 現上游。

**敗則:**若自動追敗,手設之:git branch --set-upstream-to=origin/feature/name feature/name

第三步:安換枝

換前,確工作樹淨:

# Check for uncommitted changes
git status

若有變,或提交或暫存:

# Option 1: Commit work in progress
git add <files>
git commit -m "wip: save progress on validation logic"

# Option 2: Stash changes temporarily
git stash push -m "validation work in progress"

# Switch branches
git checkout main

# Later, restore stashed changes
git checkout feature/add-weighted-mean
git stash pop

列並管暫存:

# List all stashes
git stash list

# Apply a specific stash (without removing it)
git stash apply stash@{1}

# Drop a stash
git stash drop stash@{0}

**得:**換枝成。工作樹反目標枝之態。暫存之變可復。

**敗則:**若未提交之變將被蓋而阻換,先暫存或提交。git stash 不暫未追之檔,除非用 git stash push -u

第四步:與上游同

保特性枝於基枝為新:

# Fetch latest changes
git fetch origin

# Rebase onto latest main (preferred — keeps linear history)
git rebase origin/main

# Or merge main into your branch (creates merge commit)
git merge origin/main

**得:**枝今含 main 之新變。無衝突,或衝突已解(見 resolve-git-conflicts)。

**敗則:**若 rebase 致衝突,解之並 git rebase --continue。若衝突過複雜,以 git rebase --abort 止之並改用 git merge origin/main

第五步:清已合之枝

PR 合後,除陳枝:

# Delete a local branch that has been merged
git branch -d feature/add-weighted-mean

# Delete a local branch (force, even if not merged)
git branch -D feature/abandoned-experiment

# Delete a remote branch
git push origin --delete feature/add-weighted-mean

# Prune remote-tracking references for deleted remote branches
git fetch --prune

**得:**已合之枝於本地與遠端皆除。git branch 僅現活枝。

敗則:git branch -d 拒刪未合之枝。若於 GitHub 以 squash 合併,Git 或不識之為已合。若確工已存,用 git branch -D

第六步:列並察枝

# List local branches
git branch

# List all branches (local and remote)
git branch -a

# List branches with last commit info
git branch -v

# List branches merged into main
git branch --merged main

# List branches NOT yet merged
git branch --no-merged main

# See which remote branch each local branch tracks
git branch -vv

**得:**諸枝、其態、與追關係皆明。

**敗則:**若遠端枝似陳,行 git fetch --prune 以清已刪遠端枝之參。

  • 枝名循所議命名慣
  • 特性枝自正基枝所建
  • 本地枝追其遠端對應
  • 已合之枝已清(本地與遠端)
  • 換枝前工作樹淨
  • 暫存之變不遺孤

  • 直於 main 上工:恆建特性枝。直提 main 致難建 PR 與協
  • 枝前忘取:自陳本地 main 建枝意自始已落。恆先 git fetch origin
  • 長壽枝:特性枝歷週積合併衝突。常同並保枝短壽
  • 孤之暫存git stash 乃暫存。勿依之為長工。提交或建枝
  • 刪未合之工git branch -D 乃毀。強刪前以 git log branch-name 二察
  • 不剪:於 GitHub 刪之遠端枝本地仍現,至 git fetch --prune 乃清

  • commit-changes — 於枝提交工
  • create-pull-request — 自特性枝開 PR
  • resolve-git-conflicts — 同步中處衝突
  • configure-git-repository — 倉之設與枝之略

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan/skills/manage-git-branches
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill