Cheatsheet Git

Panduan referensi cepat untuk perintah Git penting. Cheatsheet yang dapat dicari mencakup branch, commit, merge, dan banyak lagi.

Alur Kerja Pengembangan Tim

Di lingkungan profesional, tim biasanya mengikuti strategi branching di mana setiap tugas mendapat branch sendiri. Ini mengisolasi fitur dan mencegah kode yang belum selesai merusak aplikasi utama.

💡

Tips Profesional: Selalu berusaha untuk commit kecil dan atomik. Sebelum menggabungkan pekerjaan Anda, gunakan 'git fetch' lalu 'git rebase origin/dev' (atau main) untuk memastikan kode Anda kompatibel dengan versi terbaru. Terakhir, gunakan 'git push -f' pada branch fitur Anda untuk memperbarui remote dengan riwayat yang telah direbase.

Konfigurasi

Atur konfigurasi global

git config --global user.name "[name]" git config --global user.email "[email]"

Mengkonfigurasi identitas Anda di semua repositori pada sistem Anda.

Mulai

Buat repositori git

git init

Menginisialisasi repositori Git baru di direktori saat ini.

Klon repositori git yang ada

git clone [url]

Menyalin repositori Git yang ada dari server remote.

Commit

Commit semua perubahan yang dilacak

git commit -am "[commit message]"

Menyiapkan dan melakukan commit semua file yang dilacak yang dimodifikasi dalam satu perintah.

Tambahkan modifikasi baru ke commit terakhir

git commit --amend

Memperbarui commit terakhir dengan perubahan saat ini dan opsional mengubah pesan.

Branching

Buat branch baru

git branch [branch-name]

Membuat branch baru pada pointer saat ini.

Beralih ke branch

git checkout [branch-name]

Mengalihkan HEAD ke branch yang ditentukan.

Gabungkan branch ke branch saat ini

git merge [branch-name]

Menggabungkan riwayat dari branch lain ke branch Anda saat ini.

Buat dan beralih ke branch

git checkout -b [branch-name]

Cara paling umum untuk mulai mengerjakan fitur baru.

Sinkronisasi

Ambil pembaruan dari remote

git fetch

Mengunduh perubahan remote tanpa menggabungkannya.

Ambil perubahan terbaru

git pull

Mengambil perubahan dan segera mencoba menggabungkannya.

Rebase branch saat ini pada main

git rebase main

Memutar ulang commit Anda di atas branch main terbaru.

Push perubahan (Force)

git push -f

Memaksa pembaruan branch remote dengan riwayat lokal Anda. Gunakan hanya pada branch pribadi!

Perintah Berguna

Periksa status

git status

Lihat file mana yang dimodifikasi, disiapkan, atau tidak dilacak.

Simpan perubahan sementara

git stash

Menyembunyikan perubahan sementara untuk mengerjakan hal lain.

Lihat riwayat

git log --oneline --graph --all

Memvisualisasikan riwayat commit di semua branch.

Cara Menggunakan Cheatsheet Git Ini

  1. Browse the cheatsheet to find the Git command you need.
  2. Commands are organized by category: Configuration, Get Started, Commit, Branching, Syncing, and Useful Commands.
  3. Click the copy button next to any command to copy it to your clipboard.
  4. Paste the command into your terminal and modify the placeholder values as needed.

Advanced Rebasing

Rebasing is often preferred over merging to maintain a clean, linear project history. Instead of creating a 'merge commit', it repositions your commits at the end of the target branch.

Tip

Remember: Never rebase a public branch that others are working on, as it rewrites history and can cause significant conflicts for your peers.

Key Features

  • Essential Git commands organized by workflow category
  • One-click copy for every command
  • Clear descriptions explaining what each command does
  • Covers configuration, branching, syncing, and more
  • Team workflow guidance with professional tips
  • Rebasing best practices and safety warnings
  • Works offline once loaded in your browser

Common Use Cases

  • Quick reference while working in the terminal
  • Onboarding new developers to Git workflows
  • Reviewing branching and merging strategies
  • Learning Git commands for the first time
  • Refreshing memory on less frequently used commands
  • Setting up Git configuration on a new machine

Pertanyaan yang Sering Diajukan

What is the difference between git merge and git rebase?

Git merge creates a new merge commit that combines two branches, preserving the full history. Git rebase replays your commits on top of the target branch, creating a linear history. Rebase produces a cleaner log but should never be used on shared public branches.

When should I use git stash?

Use git stash when you need to switch branches but have uncommitted changes you are not ready to commit. Stash saves your working directory state temporarily. You can restore it later with 'git stash pop' on any branch.

Is it safe to use git push --force?

Force pushing is safe only on branches that you alone work on, such as personal feature branches. Never force push to shared branches like main or develop, as it rewrites remote history and can cause other team members to lose their work.

Alat Terkait