Git Cheat Sheet
๐ง Git Cheat Sheet
๐ง Setup
1git config --global user.name "Your Name"2git config --global user.email "you@example.com"3git config --global core.editor "code --wait"
๐ Memulai Repository
1git init # Buat repo baru2git clone <url> # Clone repo dari remote
๐ Workflow Dasar
1git status # Cek status file2git add <file> # Stage file tertentu3git add . # Stage semua file4git commit -m "pesan" # Commit dengan pesan5git push # Push ke remote6git pull # Tarik perubahan terbaru
๐ฟ Branching & Merging
1git branch # Lihat semua branch2git branch <nama> # Buat branch baru3git checkout <nama> # Pindah ke branch4git checkout -b <nama> # Buat + pindah ke branch baru5git merge <branch> # Gabungkan branch ke saat ini
๐ Remote Repository
1git remote -v # Tampilkan remote yang ada2git remote add origin <url> # Tambahkan remote baru3git push -u origin <branch> # Push dan set upstream
๐ต๏ธ Melihat Riwayat
1git log # Tampilkan log lengkap2git log --oneline # Tampilkan log ringkas3git diff # Lihat perubahan belum distage4git diff --staged # Lihat perubahan yang sudah distage
โ Membatalkan Perubahan
1git restore <file> # Kembalikan perubahan lokal2git restore --staged <file> # Unstage file3git reset --soft HEAD~1 # Undo commit terakhir (simpan perubahan)4git reset --hard HEAD~1 # Undo commit terakhir (hapus perubahan)
๐ฆ Stash (Simpan Sementara)
1git stash # Simpan sementara perubahan2git stash list # Lihat daftar stash3git stash pop # Terapkan dan hapus stash4git stash apply # Terapkan stash tanpa menghapus
๐งผ Membersihkan Repo
1git clean -fd # Hapus file/folder untracked
๐งช Lanjutan
1git rebase <branch> # Rebase dari branch lain2git cherry-pick <commit> # Ambil commit tertentu3git tag <tag-name> # Tandai commit
Berikut adalah Git Workflow Cheatsheet Lengkap untuk Developer, dirancang agar kamu bisa kerja cepat, rapi, dan sesuai standar tim. Cocok untuk GitHub, GitLab, Bitbucket, dan CI/CD modern (Vercel, Netlify, dll).
๐งพ GIT WORKFLOW CHEATSHEET โ FULL VERSION
๐ 1. Sync branch utama
1git checkout main # Pindah ke branch utama2git pull origin main # Ambil update terbaru dari remote
๐ฟ 2. Buat branch baru
1git checkout -b feature/123-deskripsi-singkat2# Format: <type>/<issue-id>-<deskripsi-kebab-case>
๐งโ๐ป 3. Kerja di branch โ Commit perubahan
1git status # Lihat file yang berubah2git add . # Stage semua perubahan3git commit # Buka editor dengan template4# atau langsung:5git commit -m "feat(login): tambah form login pengguna"
โฌ๏ธ 4. Push ke remote
1git push origin HEAD # Push branch saat ini
๐ 5. Buat Pull Request
- Di GitHub/GitLab/Bitbucket
- Judul:
feat: Tambah halaman login
- Deskripsi: Jelaskan apa yang diubah, referensikan issue (
#123
) - Assign reviewer
๐ 6. Review + Merge
- Lakukan code review
- Jika sudah OK, merge (squash preferred) ke
main
- Hapus branch jika tidak diperlukan
๐ 7. CI/CD (otomatis)
- Branch preview deploy (Vercel, Netlify, dsb)
- Merge ke
main
โ deploy ke production
๐ฆ Tipe Branch
Tipe | Kegunaan | Contoh Branch |
---|---|---|
feature | Fitur baru | feature/123-login-page |
bugfix | Perbaikan bug | bugfix/321-fix-navbar |
hotfix | Patch darurat (prod) | hotfix/911-critical-error |
refactor | Perbaikan struktur kode | refactor/202-clean-auth |
docs | Dokumentasi | docs/update-readme |
chore | Tugas rutin (build, deps) | chore/upgrade-dependencies |
test | Unit test / integrasi | test/add-login-tests |
๐ง Conventional Commits (Format Commit)
1<type>(<scope>): <deskripsi singkat>2
3Contoh:4feat(auth): tambahkan login dengan Google5fix(form): perbaiki validasi email kosong6refactor(auth): pisahkan middleware auth7docs(readme): perbarui petunjuk instalasi
๐งผ Branch Cleanup
1git branch -d nama-branch # Hapus branch lokal2git push origin --delete nama-branch # Hapus branch di remote
๐งฐ Lainnya
Undo changes
1git restore file.js # Batalin perubahan lokal2git reset HEAD~1 # Undo 1 commit terakhir (local)3git revert <hash> # Buat commit baru yang membatalkan perubahan
Cek commit log
1git log --oneline --graph --all
Fetch semua + prune
1git fetch --all --prune
๐ ๏ธ Tools Tambahan Disarankan
Tool | Fungsi |
---|---|
Husky | Hook Git (cek commit format, tes sebelum push, dll) |
Commitlint | Validasi format commit (Conventional Commits) |
Semantic-release | Rilis otomatis berdasarkan commit |
GitHub CLI | gh pr create , gh pr merge , dll. |
Kalau kamu mau, aku bisa kirim versi PDF / markdown / Notion dari cheatsheet ini. Atau mau aku bantu setup proyek Git kamu agar semua otomatis (template .gitmessage
, husky
, CI/CD, dll)?