Tips & Tricks (अपडेट: 2/6/2026)

Claude Code Git Workflow: साफ branch, छोटे commit, CI और team handoff

Claude Code के लिए सुरक्षित Git workflow: branch, staging, commit, rebase, CI, rollback और handoff.

Claude Code Git Workflow: साफ branch, छोटे commit, CI और team handoff

Claude Code जितनी तेजी से code लिखता है, Git workflow उतना ही साफ होना चाहिए। AI कुछ मिनटों में उपयोगी diff बना सकता है, लेकिन वही AI unrelated files मिला सकता है, बहुत बड़ा commit बना सकता है, conflict को business intent समझे बिना हल कर सकता है, या local checks चलाए बिना push कर सकता है।

यह guide solo development और team development दोनों के लिए practical Claude Code Git workflow देती है: clean branch loop, छोटे commits, review gate, worktree hygiene, conflict handling, safe rollback, push से पहले CI, और daily handoff। हम staging, commit और rebase जैसे शब्दों को आसान भाषा में समझेंगे और copy-paste commands देंगे।

साथ में पढ़ें: Claude Code Git conflict resolution, advanced GitHub Actions, और review workflow checklist। Official references: Claude Code hooks, Claude Code headless mode, Git user manual, Git rebase, GitHub Actions workflow syntax, और pre-commit

Git terms को आसान भाषा में समझें

working tree वह जगह है जहां files अभी edit हो रही हैं। Claude Code भी यहीं बदलाव करता है। staging area को “अगले commit की टोकरी” समझें। git add permanent save नहीं है; यह सिर्फ चुनता है कि अगली commit में क्या जाएगा।

commit staged changes का नाम वाला snapshot है। अच्छा commit छोटा होता है और उसका कारण साफ होता है। rebase का मतलब है अपनी branch के commits को updated main के ऊपर फिर से रखना। इससे history clean दिखती है, लेकिन जिस branch को team ने already use कर लिया है उस पर careless rebase dangerous हो सकता है।

Claude Code को सिर्फ code generator न मानें। एक मजबूत workflow में वह diff पढ़ता है, stage करने लायक files सुझाता है, commit message draft करता है, conflict के दोनों sides समझाता है, local checks चलाता है और handoff note छोड़ता है।

flowchart LR
  A["Goal लिखें"] --> B["main update करके branch बनाएं"]
  B --> C["छोटा change implement करें"]
  C --> D["diff पढ़ें और staging चुनें"]
  D --> E["review gate और local CI"]
  E --> F["छोटा commit"]
  F --> G["rebase या PR"]
  G --> H["handoff और rollback note"]

Clean branch loop

Claude Code से edit करवाने से पहले repository की स्थिति स्पष्ट करें। “Clean” का मतलब हमेशा zero changes नहीं है; मतलब यह है कि इस task से unrelated changes mix नहीं हैं।

git status --short
git fetch origin
git switch main
git pull --ff-only origin main
git switch -c feature/checkout-coupon-validation
git status --short

PowerShell में date-stamped branch कई sessions के बीच confusion कम करती है।

$topic = "checkout-coupon-validation"
$date = Get-Date -Format "yyyyMMdd"
git fetch origin
git switch main
git pull --ff-only origin main
git switch -c "feature/$date-$topic"
git status --short

पहला prompt implementation से पहले scope तय करे।

Goal: add coupon expiry validation to checkout.
Scope: edit only src/checkout, src/coupons, and matching tests.
Do not stage, commit, push, or edit unrelated files.
Before editing, read package.json and existing checkout tests.
After editing, show git diff --stat and the exact test commands you ran.

ClaudeCodeLab पर Masa ने practical problem देखा: article edit task में product draft, local report या scripts भी diff में आ गए। Build pass था, लेकिन change explain करना मुश्किल था। इसलिए prompt में “क्या नहीं छूना” उतना ही जरूरी है जितना “क्या बनाना है”।

Staging सोच-समझकर करें

git add -A convenient है, लेकिन AI-assisted work में बहुत broad है। यह temporary files, local config और दूसरे task की changes भी stage कर सकता है।

git diff --stat
git diff
git add src/checkout/validateCoupon.ts
git add tests/checkout/validateCoupon.test.ts
git diff --staged --stat
git diff --staged

Commit message searchable होना चाहिए।

git commit -m "feat(checkout): validate coupon expiry before payment"

अगर change readers, users या revenue path को affect करता है, body add करें।

git commit -m "fix(content): keep Claude Code Git workflow CTA localized" -m "Updates the localized article body, internal links, and review checklist so translated pages follow the same Git workflow."

Claude Code को message suggest करने दें, commit चलाने न दें।

Read only the staged diff.
Propose one Conventional Commits message.
Do not run git commit.
Mention the user impact in the body if the change affects readers or customers.

CLAUDE.md में Git rules रखें

CLAUDE.md project में Claude Code के लिए operating rules है। यह user README नहीं, बल्कि AI pair programmer का rulebook है।

# Claude Code Git rules

- Start every coding task with `git status --short` and report unrelated dirty files.
- Do not run `git add -A`, `git commit`, `git push`, `git reset --hard`, or `git clean -fd` unless the user explicitly asks.
- Keep commits small: one behavior change, one test update, or one content slug at a time.
- Before proposing a commit, show `git diff --stat` and `git diff --staged --stat`.
- If a conflict appears, explain both sides before editing the conflicted file.
- Run the closest local checks before push: lint, typecheck, test, build, or article metadata checks.
- Leave a handoff note with changed files, commands run, failing checks, and rollback option.

Team setup में hook भी जोड़ें। Claude Code hooks ऐसे user-defined commands हैं जो tool use जैसे lifecycle events पर चलते हैं।

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "if": "Bash(git *)",
            "command": "node .claude/hooks/block-dangerous-git.mjs"
          }
        ]
      }
    ]
  }
}
// .claude/hooks/block-dangerous-git.mjs
import process from "node:process";

let raw = "";
for await (const chunk of process.stdin) raw += chunk;

const input = JSON.parse(raw || "{}");
const command = input.tool_input?.command ?? "";

const blocked = [
  /git\s+reset\s+--hard\b/,
  /git\s+clean\s+-[^\s]*f/,
  /git\s+push\s+--force(?!-with-lease)/,
  /git\s+checkout\s+--\s+\./,
  /git\s+restore\s+\.\b/
];

if (blocked.some((pattern) => pattern.test(command))) {
  process.stderr.write(`Blocked risky Git command: ${command}\n`);
  process.exit(2);
}

Hook guardrail है, पूरी सुरक्षा policy नहीं। Human terminal commands और CI review फिर भी जरूरी हैं।

Push से पहले local CI

Remote CI fail होने का इंतजार न करें। Project में जो scripts मौजूद हैं, वही चलाने वाला preflight रखें।

// scripts/claude-git-preflight.mjs
import { execSync } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";

const run = (command) => {
  console.log(`\n$ ${command}`);
  execSync(command, { stdio: "inherit", shell: true });
};

run("git diff --check");
run("git diff --cached --check");
run("git status --short");

const pkg = existsSync("package.json")
  ? JSON.parse(readFileSync("package.json", "utf8"))
  : { scripts: {} };

for (const script of ["lint", "typecheck", "test", "build"]) {
  if (pkg.scripts?.[script]) run(`npm run ${script}`);
}
node scripts/claude-git-preflight.mjs

Claude Code prompt:

After implementation, run the local preflight.
If a command fails, stop and explain the first failing command, likely cause, and smallest next fix.
Do not push until the preflight is green.

pre-commit और GitHub Actions

pre-commit commit बनने से पहले checks चलाता है।

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: git-diff-check
        name: git diff whitespace check
        entry: git diff --check
        language: system
        pass_filenames: false
      - id: npm-test
        name: npm test when available
        entry: node scripts/claude-git-preflight.mjs
        language: system
        pass_filenames: false
python -m pip install pre-commit
pre-commit install
pre-commit run --all-files

PR में GitHub Actions वही checks clean runner पर दोहराता है।

# .github/workflows/claude-code-pr-gate.yml
name: Claude Code PR Gate

on:
  pull_request:
    branches: [main]

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm

      - run: npm ci
      - run: git diff --check origin/main...HEAD
      - run: npm run lint --if-present
      - run: npm run typecheck --if-present
      - run: npm test --if-present
      - run: npm run build --if-present

Conflict, rebase और rollback

Conflict का मतलब है Git automatic choice नहीं कर पा रहा। Claude Code से पहले दोनों sides की intent explain करवाएं।

git fetch origin
git rebase origin/main
git status --short
git diff --name-only --diff-filter=U
We are in a rebase conflict.
For each conflicted file, explain what our branch changed and what origin/main changed.
Resolve only after explaining the business intent.
After editing, run the narrowest relevant test.
Do not continue the rebase until I approve the resolved diff.
git add src/checkout/validateCoupon.ts
npm test -- --runInBand validateCoupon
git rebase --continue

अगर direction गलत लगे:

git rebase --abort

Shared commit वापस करना हो तो git revert बेहतर है।

git log --oneline -5
git revert --no-edit HEAD
git status --short

Uncommitted file के लिए exact path restore करें।

git restore --staged src/checkout/validateCoupon.ts
git restore src/checkout/validateCoupon.ts

Practical use cases और failure modes

Use case 1: solo feature. feature/yyyyMMdd-topic branch बनाएं, Claude Code को exact files और tests तक सीमित रखें, एक behavior per commit रखें, push से पहले preflight चलाएं।

Use case 2: team PR. Implementation session commit न करे। Review session सिर्फ staged diff पढ़े। Human PR title, CI, risk और rollback confirm करे।

Use case 3: content और product update. ClaudeCodeLab में articles, Gumroad links, training CTA और internal links revenue से जुड़े हैं। Slug और locale के हिसाब से काम करें, description, hero, CTA, links और localization check करें।

Use case 4: long refactor. पहले tests, फिर internal implementation, आखिर में deletion। पूरी migration को एक commit में न रखें।

Failureकारणरोकथाम
git add -A unrelated files stage करता हैAI ने scope से बाहर छुआpath से stage करें
बहुत बड़ा commitimplementation, tests, config mixएक commit, एक goal
conflict गलत solveintent नहीं समझीours/theirs पहले explain
rebase के बाद risky pushlocal और remote history अलगteam rule के साथ --force-with-lease
PR redlocal checks नहीं चलेpreflight run करें
destructive rollbackreset --hardshared commit पर git revert

Daily handoff

Handoff short और verifiable होना चाहिए।

## Handoff: 2026-06-02

Branch: feature/20260602-checkout-coupon-validation
Goal: validate coupon expiry before payment authorization

Changed:
- src/checkout/validateCoupon.ts
- tests/checkout/validateCoupon.test.ts

Checks:
- npm run lint: passed
- npm test -- --runInBand validateCoupon: passed
- npm run build: not run, no UI/build config touched

Risk:
- Coupon timezone boundary still needs one integration test.

Rollback:
- Revert commit `abc1234` if production checkout rejects valid coupons.

अगला कदम

Solo practice के लिए free Claude Code cheatsheet से शुरुआत करें। Reusable prompts, CLAUDE.md rules और review templates चाहिए तो ClaudeCodeLab products देखें। Team को real repository पर branch rules, CI, permissions, rollback और handoff set करना हो तो Claude Code training और consultation practical route है।

लागू करने पर परिणाम

ClaudeCodeLab content updates में यह loop लगाने के बाद review “सब कुछ फिर से पढ़ो” से बदलकर “slug, locale, metadata, CTA और diff scope देखो” हो गया। git diff --staged --stat और handoff सबसे उपयोगी निकले, क्योंकि वे बताते हैं कि असल में क्या verify हुआ और क्या risk बचा है।

#claude-code #git #workflow #ci #code-review #team-development
मुफ़्त

मुफ़्त PDF: Claude Code cheatsheet

Email डालें और commands, review habits तथा safe workflow वाली एक-page PDF पाएँ.

हम आपका data सुरक्षित रखते हैं और spam नहीं भेजते.

Masa

लेखक के बारे में

Masa

Claude Code workflow और team adoption पर काम करने वाला engineer.