Tool kelas lanjut yang jarang diajarkan di tutorial dasar — tapi sekali tahu, produktivitas melompat.
1. git worktree — banyak folder, satu repo
Masalah klasik: sedang di tengah fitur, ada hotfix darurat di main. Stash? Commit WIP? Worktree memberi solusi lebih bersih — dua folder terpisah, satu repo.
$ git worktree add ../hotfix main
# ../hotfix sekarang berisi main, siap diedit
# folder asli tetap di branch fitur-mu, tidak perlu stash
Struktur:
proyek/ ← worktree utama, di fitur-x
proyek-hotfix/ ← worktree kedua, di main
Hapus setelah selesai:
$ git worktree remove ../hotfix
$ git worktree list # lihat semua worktree
Kegunaan lain:
- Build di satu worktree sambil lanjut coding di yang lain
- Test di multiple branch tanpa sering checkout
- CI/CD lokal di worktree terpisah
2. git blame — siapa nulis baris ini
$ git blame src/app.js
abc1234 (Alice 2024-03-10) function login() {
def5678 (Bob 2024-03-12) validateEmail(email);
Opsi berguna:
$ git blame -L 10,20 file # hanya baris 10-20
$ git blame -w file # abaikan whitespace-only changes
$ git blame --since=1.month file # hanya perubahan bulan terakhir
Blame bukan untuk menyalahkan — pakai untuk memahami kenapa kode begini, lalu
git show <hash>untuk konteks lengkap commit.
3. Pickaxe git log -S — kapan string ini ada?
$ git log -S"validateEmail" --oneline
def5678 tambah validasi email
9876abc refactor form login
-S"text" mencari perubahan di mana jumlah kemunculan string ini berubah — artinya string ditambah atau dihapus di commit tersebut. Jauh lebih akurat dari git log --all --full-history -- file | grep.
Pakai -G"regex" untuk pola regex. --pickaxe-all menampilkan semua file yang terpengaruh.
4. git log -p -- path — history file penuh
$ git log -p -- src/auth.js
# menampilkan setiap commit yang menyentuh file + diff-nya
Tambahkan --follow supaya mengikuti rename:
$ git log --follow -p -- src/auth.js
5. git shortlog — ringkasan kontributor
$ git shortlog -sn --since=1.year
142 Alice
87 Bob
45 Charlie
-s = summary (hanya jumlah), -n = sort by count, -e = tampilkan email. Berguna untuk changelog atau credits.
6. Signed commits — bukti kamu yang commit
Tanpa signing, siapa saja bisa commit atas nama siapa saja (ubah git config user.name). Signing memverifikasi kamu punya private key.
GPG signing (klasik):
$ git config --global user.signingkey ABCD1234
$ git config --global commit.gpgsign true
$ git commit -m "pesan" # otomatis di-sign
SSH signing (lebih simpel, Git 2.34+):
$ git config --global gpg.format ssh
$ git config --global user.signingkey ~/.ssh/id_ed25519.pub
$ git config --global commit.gpgsign true
Upload public key ke GitHub (Settings → SSH and GPG keys → "Signing Key"). Commit kamu akan muncul badge "Verified" di GitHub.
Sign tag juga:
$ git tag -s v1.0 -m "release 1.0"
Kenapa penting? Supply-chain attack — penyerang bisa push commit atas nama maintainer. Signed commits + branch protection "require signed commits" menghentikan ini.