Git'in temel kavramlarından ileri seviye tekniklerine kadar kapsamlı Türkçe kılavuz
- 🔰 Git Temelleri
- 🌿 Branch (Dal) İşlemleri
- 📤 Push ve Pull İşlemleri
- 🔄 Merge ve Rebase
- 📝 Commit İşlemleri
- 🔍 Geçmiş ve Log İşlemleri
- 🏷️ Tag İşlemleri
- 🔧 Konfigürasyon
- ⚡ İleri Seviye Komutlar
- 🛠️ Sorun Giderme
- 📊 Git Workflow Örnekleri
# Yeni bir git repository'si başlatma
git init
# Mevcut bir repository'yi klonlama
git clone <repository-url>
# Belirli bir branch'i klonlama
git clone -b <branch-name> <repository-url>
# Shallow clone (sadece son commit)
git clone --depth 1 <repository-url># Repository durumunu kontrol etme
git status
# Kısa format ile durum görme
git status -s
# Dosyaları staging area'ya ekleme
git add <dosya-adı>
git add . # Tüm dosyalar
git add *.js # Belirli uzantıdaki dosyalar
git add -A # Tüm değişiklikler (silinen dosyalar dahil)
# Staging area'dan dosya çıkarma
git reset HEAD <dosya-adı>
git restore --staged <dosya-adı>
# Dosyadaki değişiklikleri geri alma
git checkout -- <dosya-adı>
git restore <dosya-adı># Commit oluşturma
git commit -m "Commit mesajı"
# Staging ve commit'i birlikte yapma
git commit -am "Commit mesajı"
# Son commit'i düzenleme
git commit --amend -m "Yeni commit mesajı"
# Boş commit oluşturma
git commit --allow-empty -m "Empty commit"# Mevcut branch'leri listeleme
git branch # Local branch'ler
git branch -r # Remote branch'ler
git branch -a # Tüm branch'ler
# Yeni branch oluşturma
git branch <branch-adı>
# Branch oluşturup geçiş yapma
git checkout -b <branch-adı>
git switch -c <branch-adı> # Modern syntax
# Belirli bir commit'ten branch oluşturma
git checkout -b <branch-adı> <commit-hash>
# Remote branch'ten local branch oluşturma
git checkout -b <local-branch> origin/<remote-branch># Mevcut local branch'e geçiş
git checkout <branch-adı>
git switch <branch-adı> # Modern syntax (Git 2.23+)
# Önceki branch'e geri dönme
git checkout -
git switch -
# Branch'i oluşturup hemen geçiş yapma
git checkout -b <yeni-branch>
git switch -c <yeni-branch> # Modern syntax
# Belirli commit'ten branch oluşturup geçiş
git checkout -b <branch-adı> <commit-hash>
git switch -c <branch-adı> <commit-hash># Remote branch'leri görme
git branch -r # Sadece remote branch'ler
git branch -a # Tüm branch'ler (local + remote)
# Remote branch'e geçiş (otomatik tracking)
git checkout <remote-branch-adı>
git switch <remote-branch-adı>
# Remote branch'ten local branch oluşturup geçiş
git checkout -b <local-branch> origin/<remote-branch>
git switch -c <local-branch> origin/<remote-branch>
# Farklı remote'tan branch tracking
git checkout -b <local-branch> <remote-name>/<remote-branch>
# Mevcut branch'i remote branch ile ilişkilendirme
git branch --set-upstream-to=origin/<branch-adı>
git push -u origin <branch-adı> # Push ile birlikte upstream ayarlama# Uncommitted değişiklikler varken güvenli geçiş
git stash push -m "Geçici kayıt: $(git branch --show-current)"
git checkout <hedef-branch>
git stash pop # Değişiklikleri geri getirme
# Belirli dosyaları stash'leyip geçiş
git stash push -m "Sadece belirli dosyalar" <dosya1> <dosya2>
git checkout <branch-adı>
# Değişiklikleri commit etmeden geçiş (dikkatli!)
git checkout <branch-adı> --force # Değişiklikler kaybolur!
# Working directory temizliği kontrolü
git status --porcelain | wc -l # 0 ise temiz# Mevcut branch'i öğrenme
git branch --show-current
git rev-parse --abbrev-ref HEAD
# Son değişiklikleri görme
git status --short
git diff --name-only
# Branch'ler arası fark kontrolü
git diff <branch1>..<branch2> --name-only
git log <branch1>..<branch2> --oneline
# Remote tracking durumu
git remote show origin
git branch -vv # Tracking bilgileri ile branch listesi# Tüm remote branch'leri local'e çekme
git fetch --all
for branch in $(git branch -r | grep -v HEAD | sed 's/origin\///'); do
git checkout -b $branch origin/$branch 2>/dev/null || true
done
# Tüm local branch'lerde dolaşma (örnek script)
for branch in $(git branch --format='%(refname:short)'); do
echo "=== $branch ==="
git checkout $branch
# İstediğiniz işlemleri yapın
done
# Ana branch'e dönme
git checkout main || git checkout master# Faydalı alias'lar tanımlama
git config --global alias.sw "switch"
git config --global alias.co "checkout"
git config --global alias.cob "checkout -b"
git config --global alias.com "checkout main"
git config --global alias.cod "checkout develop"
# Son kullanılan branch'leri gösterme
git reflog | grep checkout | head -10
# Branch geçmişi
git reflog --grep-reflog="checkout:"# Local branch silme
git branch -d <branch-adı> # Güvenli silme
git branch -D <branch-adı> # Zorla silme
# Remote branch silme
git push origin --delete <branch-adı>
git push origin :<branch-adı>
# Silinen remote branch referanslarını temizleme
git remote prune origin# Değişiklikleri remote'a gönderme
git push origin <branch-adı>
# İlk push (upstream ayarlama)
git push -u origin <branch-adı>
# Tüm branch'leri push etme
git push --all origin
# Tag'leri push etme
git push --tags origin
# Zorla push (dikkatli kullanın!)
git push --force origin <branch-adı>
git push --force-with-lease origin <branch-adı> # Güvenli versiyon# Remote'dan güncellemeleri çekme
git pull origin <branch-adı>
# Tüm remote branch'lerin güncellemelerini çekme
git fetch --all
# Rebase ile pull yapma
git pull --rebase origin <branch-adı>
# Specific remote'dan pull
git pull <remote-name> <branch-adı># Remote repository'leri listeleme
git remote -v
# Remote ekleme
git remote add <remote-adı> <url>
# Remote URL'ini değiştirme
git remote set-url origin <yeni-url>
# Remote silme
git remote remove <remote-adı>
# Remote branch'leri güncelleme
git remote update# Branch'i mevcut branch'e merge etme
git merge <branch-adı>
# No-fast-forward merge
git merge --no-ff <branch-adı>
# Squash merge (tüm commit'leri tek commit'e çevirme)
git merge --squash <branch-adı>
# Merge conflict durumunda
git status # Çakışan dosyaları görme
# Dosyaları düzenleyin
git add <çözülen-dosya>
git commit # Merge commit'i tamamlama
# Merge'i iptal etme
git merge --abort# Branch'i başka branch üzerine rebase etme
git rebase <base-branch>
# Interactive rebase (son 3 commit)
git rebase -i HEAD~3
# Rebase'i devam ettirme
git rebase --continue
# Rebase'i iptal etme
git rebase --abort
# Rebase sırasında conflict çözme
git add <çözülen-dosya>
git rebase --continue# Belirli bir commit'i mevcut branch'e uygulama
git cherry-pick <commit-hash>
# Birden fazla commit'i cherry-pick etme
git cherry-pick <commit1> <commit2>
# Range ile cherry-pick
git cherry-pick <start-commit>..<end-commit># Son commit mesajını değiştirme
git commit --amend -m "Yeni mesaj"
# Son commit'e dosya ekleme
git add <dosya>
git commit --amend --no-edit
# Commit'i geri alma (soft reset)
git reset --soft HEAD~1
# Commit'i geri alma (hard reset)
git reset --hard HEAD~1
# Belirli bir commit'e geri dönme
git reset --hard <commit-hash># Commit geçmişini görme
git log
# Kısa format log
git log --oneline
# Grafik formatında log
git log --graph --pretty=oneline --abbrev-commit
# Belirli sayıda commit gösterme
git log -n 5
# Belirli dosyanın geçmişi
git log -- <dosya-adı>
# Commit'ler arası fark
git diff <commit1>..<commit2># Güzel formatlanmış log
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
# Son değişiklikleri gösterme
git show
# Belirli commit'in detayları
git show <commit-hash>
# Dosya değişiklik geçmişi
git blame <dosya-adı>
# Kimlerin ne zaman commit yaptığını görme
git shortlog -s -n# Working directory ile staging area farkı
git diff
# Staging area ile son commit farkı
git diff --staged
# İki commit arası fark
git diff <commit1> <commit2>
# İki branch arası fark
git diff <branch1>..<branch2>
# Sadece dosya isimlerini gösterme
git diff --name-only# Kod içinde arama
git grep "aranacak-metin"
# Commit mesajlarında arama
git log --grep="aranacak-metin"
# Yazar adına göre arama
git log --author="yazar-adı"
# Tarih aralığında arama
git log --since="2 weeks ago" --until="1 week ago"# Lightweight tag oluşturma
git tag <tag-adı>
# Annotated tag oluşturma
git tag -a <tag-adı> -m "Tag açıklaması"
# Belirli commit'e tag ekleme
git tag -a <tag-adı> <commit-hash> -m "Açıklama"
# Tag'leri listeleme
git tag
git tag -l "v1.*" # Pattern ile arama
# Tag detaylarını görme
git show <tag-adı>
# Tag'leri push etme
git push origin <tag-adı>
git push --tags # Tüm tag'ler
# Tag silme
git tag -d <tag-adı> # Local
git push origin :refs/tags/<tag-adı> # Remote# Global ayarlar
git config --global user.name "Adınız Soyadınız"
git config --global user.email "email@example.com"
# Editor ayarlama
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
# Alias'lar oluşturma
git config --global alias.st "status"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.ci "commit"
# Mevcut konfigürasyonu görme
git config --list
git config --global --list
# Belirli bir ayarı görme
git config user.name# Gelişmiş alias'lar
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.visual "!gitk"# Değişiklikleri geçici olarak saklama
git stash
git stash push -m "Açıklama"
# Belirli dosyaları stash'leme
git stash push <dosya-adı>
# Stash listesini görme
git stash list
# Stash'i uygulama
git stash pop # Son stash'i uygula ve sil
git stash apply # Son stash'i uygula ama silme
# Belirli stash'i uygulama
git stash apply stash@{2}
# Stash silme
git stash drop stash@{0}
git stash clear # Tüm stash'leri silme# Submodule ekleme
git submodule add <repository-url> <path>
# Submodule'leri güncelleme
git submodule update --init --recursive
# Submodule'leri en son versiyona çekme
git submodule update --remote
# Submodule silme
git submodule deinit <path>
git rm <path># Bug arama başlatma
git bisect start
# İyi ve kötü commit'leri belirleme
git bisect bad # Mevcut commit kötü
git bisect good <commit> # Belirli commit iyi
# Otomatik test ile bisect
git bisect run <test-script>
# Bisect'i sonlandırma
git bisect reset# Yeni worktree oluşturma
git worktree add <path> <branch>
# Worktree'leri listeleme
git worktree list
# Worktree silme
git worktree remove <path># Yanlış commit mesajını düzeltme
git commit --amend -m "Doğru mesaj"
# Yanlış dosyayı commit'ten çıkarma
git reset HEAD~1
git add <doğru-dosyalar>
git commit -m "Düzeltilmiş commit"
# Merge conflict çözme
git status # Çakışan dosyaları görme
# Dosyaları manuel olarak düzenle
git add <dosya>
git commit
# Lost commit'leri bulma
git reflog
git cherry-pick <commit-hash>
# Dosyayı önceki haline döndürme
git checkout <commit-hash> -- <dosya-adı># Untracked dosyaları silme
git clean -f # Dosyaları sil
git clean -fd # Dosya ve klasörleri sil
git clean -n # Silinecekleri göster (dry run)
# Remote tracking branch'leri temizleme
git remote prune origin
# Garbage collection
git gc # Repository'yi optimize et
git gc --aggressive # Agresif temizlik# 1. Ana branch'ten yeni feature branch'i oluştur
git checkout main
git pull origin main
git checkout -b feature/yeni-ozellik
# 2. Geliştirme yap
git add .
git commit -m "Yeni özellik eklendi"
# 3. Remote'a push et
git push -u origin feature/yeni-ozellik
# 4. Pull request oluştur (GitHub/GitLab'da)
# 5. Review sonrası merge et
git checkout main
git pull origin main
git branch -d feature/yeni-ozellik# 1. Ana branch'ten hotfix branch'i oluştur
git checkout main
git checkout -b hotfix/kritik-bug
# 2. Bug'ı düzelt
git add .
git commit -m "Kritik bug düzeltmesi"
# 3. Ana branch'e merge et
git checkout main
git merge hotfix/kritik-bug
git push origin main
# 4. Hotfix branch'ini sil
git branch -d hotfix/kritik-bug# 1. Release branch'i oluştur
git checkout develop
git checkout -b release/v1.0.0
# 2. Version numarasını güncelle
# package.json, version dosyaları vs.
git add .
git commit -m "Version 1.0.0 için hazırlık"
# 3. Ana branch'e merge et
git checkout main
git merge release/v1.0.0
# 4. Tag oluştur
git tag -a v1.0.0 -m "Version 1.0.0 release"
git push origin main --tags
# 5. Develop branch'e geri merge et
git checkout develop
git merge release/v1.0.0
git push origin develop
# 6. Release branch'ini sil
git branch -d release/v1.0.0feat: yeni özellik ekleme
fix: bug düzeltmesi
docs: dokümantasyon güncellemesi
style: kod formatı değişiklikleri
refactor: kod refactoring
test: test ekleme/düzenleme
chore: build process, dependency güncellemeleri
# Pre-commit hook (test çalıştırma)
#!/bin/sh
npm test
if [ $? -ne 0 ]; then
echo "Tests failed, commit aborted"
exit 1
fi# Büyük dosyalar için
git config core.preloadindex true
git config core.fscache true
git config gc.auto 256
# Partial clone (büyük repository'ler için)
git clone --filter=blob:none <url>Dikkat:
--forceparametresi kullanan komutlar tehlikeli olabilir. Kullanmadan önce durumu iyice analiz edin.
İpucu: Komutları denemeden önce
--dry-runparametresi ile test edebilirsiniz.
Öneriler: Düzenli olarak
git statuskomutu ile durumu kontrol edin.
🎯 Bu kılavuz sürekli güncellenmektedir. Katkılarınızı bekliyoruz!
Made with ❤️ by developers, for developers