Tips & Tricks (Diperbarui: 2/6/2026)

Workflow Git Claude Code: branch bersih, commit kecil, CI, dan handoff tim

Workflow Git praktis untuk Claude Code: branch, staging, commit, rebase, CI, rollback, dan handoff.

Workflow Git Claude Code: branch bersih, commit kecil, CI, dan handoff tim

Semakin cepat Claude Code menulis kode, semakin disiplin workflow Git yang dibutuhkan. AI bisa membuat diff berguna dalam hitungan menit, tetapi juga bisa mencampur file yang tidak terkait, membuat commit terlalu besar, menyelesaikan konflik tanpa memahami niat perubahan, atau push sebelum local checks dijalankan.

Panduan ini memberi workflow Git praktis untuk solo developer dan tim: clean branch loop, commit kecil, review gate, worktree hygiene, conflict handling, safe rollback, CI sebelum push, dan daily handoff. Istilah staging, commit, dan rebase dijelaskan dengan bahasa pemula.

Bacaan lanjutan: menyelesaikan konflik Git dengan Claude Code, GitHub Actions lanjutan, dan review workflow checklist. Referensi resmi: Claude Code hooks, Claude Code headless mode, Git user manual, Git rebase, GitHub Actions workflow syntax, dan pre-commit.

Istilah Git dengan bahasa sederhana

working tree adalah area tempat file sedang diedit. Claude Code menulis perubahan di sini. staging area adalah “keranjang commit berikutnya”. git add bukan menyimpan permanen; ia memilih perubahan mana yang masuk ke commit berikutnya.

commit adalah snapshot bernama dari perubahan yang sudah staged. Commit yang baik cukup kecil untuk dipahami reviewer. rebase berarti memindahkan commit di branch kamu agar berada di atas main terbaru. Riwayat jadi rapi, tetapi rebase pada branch yang sudah dipakai orang lain bisa merusak alur kerja mereka.

Claude Code jangan dipakai hanya sebagai generator kode. Dalam workflow yang aman, ia juga membaca diff, menyarankan file yang perlu di-stage, membuat draft commit message, menjelaskan konflik, menjalankan checks lokal, dan menulis handoff.

flowchart LR
  A["Tulis tujuan"] --> B["Update main dan buat branch"]
  B --> C["Implementasi kecil"]
  C --> D["Baca diff dan pilih staging"]
  D --> E["Review gate dan CI lokal"]
  E --> F["Commit kecil"]
  F --> G["Rebase atau PR"]
  G --> H["Handoff dan rollback"]

Mulai dari branch yang bersih

Sebelum meminta Claude Code mengedit file, pastikan status repository mudah dipahami. “Bersih” tidak selalu berarti tanpa perubahan; artinya tidak ada perubahan di luar scope yang tercampur.

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

Di PowerShell, branch dengan tanggal membantu saat beberapa sesi berjalan paralel.

$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 pertama harus menentukan 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.

Masa pernah melihat masalah ini di ClaudeCodeLab: tugas memperbarui artikel ikut membawa draft produk, script lokal, atau laporan sementara. Build tetap lolos, tetapi diff sulit dijelaskan. Scope yang jelas mengurangi biaya review.

Staging sengaja dan commit kecil

git add -A memang praktis, tetapi terlalu luas untuk kerja dengan AI. Ia dapat men-stage file sementara, konfigurasi lokal, atau perubahan dari tugas lain.

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 harus jelas dan mudah dicari.

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

Jika perubahan menyentuh pembaca, pengguna, atau jalur pendapatan, tambahkan body.

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."

Minta Claude Code membuat pesan, bukan menjalankan 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.

Simpan aturan di CLAUDE.md

CLAUDE.md adalah aturan kerja untuk Claude Code di repository. Ini bukan README pengguna, melainkan instruksi operasional untuk pair programmer AI.

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

Untuk tim, tambahkan hook yang memblokir perintah Git berisiko. Claude Code hooks adalah perintah buatan pengguna yang berjalan pada lifecycle event seperti tool use.

{
  "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 adalah pagar pengaman, bukan pengganti review dan CI.

CI lokal sebelum push

Jangan tunggu CI remote gagal. Buat preflight yang menjalankan script yang tersedia.

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

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 dan GitHub Actions

pre-commit menjalankan checks sebelum commit dibuat.

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

Di pull request, ulangi checks dengan GitHub Actions.

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

Konflik, rebase, dan rollback

Konflik berarti Git tidak bisa memilih otomatis antara dua perubahan. Minta Claude Code menjelaskan niat kedua sisi terlebih dahulu.

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

Jika salah arah:

git rebase --abort

Untuk commit yang sudah dibagikan, gunakan git revert.

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

Untuk file yang belum di-commit, targetkan path tertentu.

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

Use case dan kegagalan umum

Use case 1: fitur solo. Buat feature/yyyyMMdd-topic, batasi file dan test, satu perubahan perilaku per commit, lalu jalankan preflight sebelum push.

Use case 2: PR tim. Sesi implementasi tidak commit. Sesi review membaca staged diff saja. Manusia mengecek judul PR, CI, risiko, dan rollback.

Use case 3: konten dan halaman produk. Di ClaudeCodeLab, artikel, link Gumroad, CTA training, dan internal link memengaruhi revenue. Kerjakan per slug dan locale, lalu cek description, hero, CTA, link, dan lokalitas bahasa.

Use case 4: refactor panjang. Tambah test dulu, ubah internal kemudian, hapus kode lama terakhir. Jangan satu commit untuk semua migrasi.

KegagalanPenyebabPencegahan
git add -A memasukkan file tak terkaitAI menyentuh scope terlalu luasStage berdasarkan path
Commit terlalu besarImplementasi, test, config tercampurSatu tujuan per commit
Konflik salah resolveNiat kedua sisi tidak dibacaJelaskan ours/theirs dulu
Push berisiko setelah rebaseHistory lokal dan remote berbeda--force-with-lease sesuai aturan tim
PR merahCheck lokal tidak dijalankanJalankan preflight
Rollback destruktifMemakai reset --hardGunakan git revert untuk commit bersama

Daily handoff

Handoff harus singkat, faktual, dan mudah dilanjutkan.

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

Langkah berikutnya

Jika belajar sendiri, mulai dari cheatsheet Claude Code gratis. Jika butuh prompt reusable, aturan CLAUDE.md, dan template review, lihat produk ClaudeCodeLab. Untuk tim yang perlu menyesuaikan branch, CI, permission, rollback, dan handoff ke repository nyata, gunakan training dan konsultasi Claude Code.

Hasil saat diterapkan

Saat workflow ini dipakai untuk update konten ClaudeCodeLab, review berubah dari “baca ulang semuanya” menjadi memeriksa slug, locale, metadata, CTA, dan scope diff. git diff --staged --stat dan handoff paling membantu karena menunjukkan apa yang benar-benar diverifikasi.

#claude-code #git #workflow #ci #code-review #team-development
Gratis

PDF gratis: cheatsheet Claude Code

Masukkan email dan unduh satu halaman berisi command, kebiasaan review, dan workflow aman.

Kami menjaga datamu dan tidak mengirim spam.

Masa

Tentang penulis

Masa

Engineer yang berfokus pada workflow Claude Code praktis dan adopsi tim.