Git İleri Seviye: Rebase, Cherry-pick ve Branching Stratejileri

z

zafer ak

Yazar

02 December 2025 2 dakika okuma 2 görüntülenme
Git İleri Seviye: Rebase, Cherry-pick ve Branching Stratejileri
Git ileri düzey komutları: rebase, cherry-pick, stash, bisect. GitFlow ve trunk-based development stratejileri.

Git Branching Stratejileri

GitFlow

main (production)
├── develop
│   ├── feature/user-auth
│   ├── feature/payment
│   └── release/1.0.0
└── hotfix/critical-bug

Trunk-Based Development

main
├── feature/short-lived-branch (max 1-2 gün)
└── feature/another-feature

Git Rebase

Branch'inizi main'in üzerine taşıma:

# Feature branch'indeyken
git checkout feature/my-feature
git rebase main

# Interactive rebase (commit düzenleme)
git rebase -i HEAD~3

# Rebase sırasında conflict çözme
git add .
git rebase --continue

# Rebase iptal
git rebase --abort

Rebase vs Merge

  • Merge: History korur, merge commit oluşturur
  • Rebase: Linear history, clean log

Git Cherry-pick

Specific commit'i başka branch'e alma:

# Tek commit
git cherry-pick abc123

# Birden fazla commit
git cherry-pick abc123 def456

# Commit range
git cherry-pick abc123..def456

# Conflict durumunda
git cherry-pick --continue
git cherry-pick --abort

Git Stash

# Değişiklikleri kaydet
git stash

# Mesajla kaydet
git stash save "WIP: user form"

# Stash listele
git stash list

# Stash uygula ve sil
git stash pop

# Stash uygula, silme
git stash apply stash@{0}

# Stash sil
git stash drop stash@{0}

# Tüm stash'leri sil
git stash clear

Git Bisect

Bug'ın hangi commit'te girdiğini bulma:

git bisect start
git bisect bad                 # Şu anki commit kötü
git bisect good abc123         # Bu commit iyi

# Git otomatik olarak aradaki commit'leri test eder
# Her commit'te test edip şunu söyleyin:
git bisect good  # veya
git bisect bad

# Bulduktan sonra
git bisect reset

Git Reflog

Kayıp commit'leri kurtarma:

# Tüm hareketleri gör
git reflog

# Kayıp commit'e dön
git checkout abc123

# Veya branch oluştur
git branch recovered abc123

Git Hooks

# .git/hooks/pre-commit
#!/bin/bash
npm run lint
npm test

# Husky ile (package.json)
{
  "husky": {
    "hooks": {
      "pre-commit": "npm run lint",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }
}

Commit Message Conventions

feat: add user authentication
fix: resolve login bug
docs: update README
style: format code
refactor: restructure user service
test: add unit tests
chore: update dependencies

Git Aliases

# ~/.gitconfig
[alias]
  co = checkout
  br = branch
  ci = commit
  st = status
  lg = log --oneline --graph --all
  unstage = reset HEAD --
  last = log -1 HEAD

Sonuç

Git'in ileri seviye özelliklerini öğrenmek, development workflow'unuzu önemli ölçüde iyileştirir. Practice makes perfect!

İlgili Yazılar