GIT DOCS

SETUP-CONFIG

git config --global user.name
Description: Set nama pengguna global.
Example:
git config --global user.name "Ridho Akbar"
Output: Nama tersimpan
git config --global user.email
Description: Set email pengguna global.
Example:
git config --global user.email "ridho@email.com"
Output: Email tersimpan
git config --list
Description: Lihat semua konfigurasi Git.
Example:
git config --list
Output: user.name=Ridho...
git config --global init.defaultBranch
Description: Set default branch name (main).
Example:
git config --global init.defaultBranch main
Output: Default: main
git config --global core.editor
Description: Set editor default untuk commit message.
Example:
git config --global core.editor "code --wait"
Output: VS Code
git config --global core.autocrlf
Description: Atur line ending (true=Windows, input=Mac/Linux).
Example:
git config --global core.autocrlf true
Output: CRLF auto
git config --global alias.<shortcut>
Description: Buat shortcut perintah.
Example:
git config --global alias.co checkout
Output: git co = git checkout
git config --global --edit
Description: Edit global config file langsung.
Example:
git config --global --edit
Output: Buka .gitconfig

INIT-CLONE

git init
Description: Inisialisasi repo Git baru di folder.
Example:
git init
Output: Initialized empty Git repository
git init -b <branch>
Description: Inisialisasi dengan branch tertentu.
Example:
git init -b main
Output: Branch: main
git clone <url>
Description: Clone repo dari remote.
Example:
git clone https://github.com/user/repo.git
Output: Folder repo terdownload
git clone <url> <folder>
Description: Clone ke folder spesifik.
Example:
git clone https://github.com/user/repo.git my-project
Output: Folder: my-project
git clone --branch <branch> <url>
Description: Clone branch tertentu saja.
Example:
git clone --branch dev https://github.com/user/repo.git
Output: Branch dev
git clone --depth 1 <url>
Description: Shallow clone — hanya commit terbaru (lebih cepat).
Example:
git clone --depth 1 https://github.com/user/repo.git
Output: Ukuran kecil
git clone --single-branch <url>
Description: Clone hanya 1 branch.
Example:
git clone --single-branch --branch main <url>
Output: 1 branch saja

BASIC-SNAPSHOT

git status
Description: Cek status working directory & staging area.
Example:
git status
Output: modified: file.txt
git status -s
Description: Status singkat (short).
Example:
git status -s
Output: M file.txt
git add <file>
Description: Tambahkan file ke staging area.
Example:
git add index.html
Output: Staged
git add .
Description: Tambahkan semua perubahan ke staging.
Example:
git add .
Output: Semua staged
git add -A
Description: Tambahkan semua termasuk delete.
Example:
git add -A
Output: Semua (add, modify, delete)
git add -p
Description: Tambahkan perubahan secara interaktif (patch).
Example:
git add -p
Output: Pilih hunk per hunk
git commit -m "msg"
Description: Commit perubahan dengan pesan.
Example:
git commit -m "feat: add login page"
Output: [main a1b2c3d] feat: add login page
git commit -am "msg"
Description: Add + commit sekaligus (hanya file tracked).
Example:
git commit -am "fix: typo"
Output: Staged & committed
git commit --amend
Description: Ubah commit terakhir (pesan atau isi).
Example:
git commit --amend -m "new message"
Output: Commit terakhir diubah
git commit --amend --no-edit
Description: Tambahkan perubahan ke commit terakhir tanpa ubah pesan.
Example:
git add . && git commit --amend --no-edit
Output: Commit terakhir ditambah
git commit --allow-empty
Description: Commit kosong (untuk trigger CI/CD).
Example:
git commit --allow-empty -m "trigger build"
Output: Commit kosong
git reset <file>
Description: Unstage file (keluarkan dari staging).
Example:
git reset index.html
Output: Unstaged
git reset HEAD <file>
Description: Unstage file (sintaks lama).
Example:
git reset HEAD file.txt
Output: Unstaged
git restore --staged <file>
Description: Unstage file (cara modern).
Example:
git restore --staged file.txt
Output: Unstaged
git restore <file>
Description: Kembalikan file ke versi terakhir commit (buang perubahan).
Example:
git restore file.txt
Output: Perubahan hilang
git clean -n
Description: Lihat file untracked yang akan dihapus (dry run).
Example:
git clean -n
Output: Would remove file.txt
git clean -f
Description: Hapus file untracked.
Example:
git clean -f
Output: Removing file.txt
git clean -fd
Description: Hapus file & folder untracked.
Example:
git clean -fd
Output: Removing folder/

DIFF-LOG

git diff
Description: Lihat perubahan yang belum di-staging.
Example:
git diff
Output: + baris baru
git diff --staged
Description: Lihat perubahan yang sudah di-staging.
Example:
git diff --staged
Output: + baris staged
git diff <commit1> <commit2>
Description: Bandingkan dua commit.
Example:
git diff abc123 def456
Output: Perbedaan
git diff <branch1>..<branch2>
Description: Bandingkan dua branch.
Example:
git diff main..dev
Output: Perbedaan branch
git diff --name-only
Description: Hanya tampilkan nama file yang berubah.
Example:
git diff --name-only
Output: file1.txt file2.js
git log
Description: Lihat riwayat commit.
Example:
git log
Output: commit abc... Author: ...
git log --oneline
Description: Log ringkas 1 baris per commit.
Example:
git log --oneline
Output: a1b2c3d feat: login
git log --oneline --graph
Description: Log dengan grafik branch.
Example:
git log --oneline --graph --all
Output: * a1b2c3d (HEAD -> main)
git log -p
Description: Log dengan patch/diff setiap commit.
Example:
git log -p
Output: + baris ditambahkan
git log --stat
Description: Log dengan statistik file berubah.
Example:
git log --stat
Output: 2 files changed, 10 insertions
git log --author="name"
Description: Filter log by author.
Example:
git log --author="Ridho"
Output: Commit Ridho saja
git log --since="date"
Description: Log sejak tanggal tertentu.
Example:
git log --since="2025-01-01"
Output: Sejak 2025
git log -<n>
Description: Tampilkan n commit terakhir.
Example:
git log -5
Output: 5 commit terakhir
git show <commit>
Description: Lihat detail 1 commit.
Example:
git show a1b2c3d
Output: diff + metadata
git blame <file>
Description: Lihat siapa yang mengubah setiap baris.
Example:
git blame index.html
Output: a1b2c3d (Ridho 2025-01-01) line
git shortlog
Description: Ringkasan commit per author.
Example:
git shortlog
Output: Ridho (5): feat: ...

BRANCH

git branch
Description: Lihat daftar branch lokal.
Example:
git branch
Output: * main dev
git branch -r
Description: Lihat branch remote.
Example:
git branch -r
Output: origin/main
git branch -a
Description: Lihat semua branch (lokal + remote).
Example:
git branch -a
Output: Semua branch
git branch <nama>
Description: Buat branch baru.
Example:
git branch feature-login
Output: Branch dibuat
git checkout <branch>
Description: Pindah ke branch (cara lama).
Example:
git checkout dev
Output: Switched to branch 'dev'
git switch <branch>
Description: Pindah ke branch (cara modern).
Example:
git switch main
Output: Switched to 'main'
git switch -c <branch>
Description: Buat + pindah ke branch baru.
Example:
git switch -c feature- baru
Output: Switched to new branch
git checkout -b <branch>
Description: Buat + pindah (cara lama).
Example:
git checkout -b feature-baru
Output: Switched to new branch
git branch -d <branch>
Description: Hapus branch lokal (aman — sudah di-merge).
Example:
git branch -d feature-lama
Output: Deleted branch
git branch -D <branch>
Description: Hapus branch lokal (paksa — belum merge).
Example:
git branch -D feature-lama
Output: Deleted branch
git branch -m <old> <new>
Description: Rename branch.
Example:
git branch -m old-name new-name
Output: Renamed
git branch -m <new>
Description: Rename branch saat ini.
Example:
git branch -m new-name
Output: Renamed current

MERGE-REBASE

git merge <branch>
Description: Merge branch ke branch saat ini.
Example:
git merge feature-login
Output: Merge made by 'ort' strategy
git merge --no-ff <branch>
Description: Merge tanpa fast-forward (selalu buat merge commit).
Example:
git merge --no-ff feature
Output: Merge commit dibuat
git merge --squash <branch>
Description: Squash semua commit branch jadi 1 sebelum merge.
Example:
git merge --squash feature
Output: Siap di-commit manual
git merge --abort
Description: Batalkan merge yang sedang conflict.
Example:
git merge --abort
Output: Kembali sebelum merge
git rebase <branch>
Description: Re-apply commit di atas branch lain (history linear).
Example:
git rebase main
Output: Successfully rebased
git rebase -i <commit>
Description: Interactive rebase — squash, reword, drop commit.
Example:
git rebase -i HEAD~3
Output: Editor terbuka
git rebase --continue
Description: Lanjutkan rebase setelah resolve conflict.
Example:
git rebase --continue
Output: Rebase lanjut
git rebase --abort
Description: Batalkan rebase.
Example:
git rebase --abort
Output: Kembali sebelum rebase
git rebase --skip
Description: Lewati commit yang conflict.
Example:
git rebase --skip
Output: Commit dilewati
git cherry-pick <commit>
Description: Ambil 1 commit dari branch lain ke branch saat ini.
Example:
git cherry-pick a1b2c3d
Output: Commit dipindahkan
git cherry-pick --continue
Description: Lanjutkan cherry-pick setelah resolve.
Example:
git cherry-pick --continue
Output: Cherry-pick lanjut
git cherry-pick --abort
Description: Batalkan cherry-pick.
Example:
git cherry-pick --abort
Output: Kembali

STASH

git stash
Description: Simpan perubahan sementara (working + staging).
Example:
git stash
Output: Saved working directory
git stash -m "msg"
Description: Stash dengan pesan.
Example:
git stash -m "WIP: login"
Output: Saved with message
git stash -u
Description: Stash termasuk file untracked.
Example:
git stash -u
Output: Termasuk untracked
git stash -a
Description: Stash termasuk file ignored.
Example:
git stash -a
Output: Semua
git stash list
Description: Lihat daftar stash.
Example:
git stash list
Output: stash@{0}: WIP on main: ...
git stash pop
Description: Ambil stash terakhir & hapus dari list.
Example:
git stash pop
Output: Perubahan kembali
git stash pop stash@{n}
Description: Ambil stash ke-n.
Example:
git stash pop stash@{1}
Output: Stash ke-1 kembali
git stash apply
Description: Ambil stash terakhir TANPA hapus dari list.
Example:
git stash apply
Output: Perubahan kembali, stash tetap ada
git stash drop stash@{n}
Description: Hapus stash ke-n.
Example:
git stash drop stash@{0}
Output: Dropped
git stash clear
Description: Hapus semua stash.
Example:
git stash clear
Output: Semua stash hilang

REMOTE

git remote
Description: Lihat daftar remote.
Example:
git remote
Output: origin
git remote -v
Description: Lihat URL remote.
Example:
git remote -v
Output: origin https://github.com/...
git remote add <name> <url>
Description: Tambah remote baru.
Example:
git remote add origin https://github.com/user/repo.git
Output: Remote origin ditambahkan
git remote remove <name>
Description: Hapus remote.
Example:
git remote remove origin
Output: Remote dihapus
git remote rename <old> <new>
Description: Ganti nama remote.
Example:
git remote rename origin upstream
Output: Renamed
git remote show <name>
Description: Info detail remote.
Example:
git remote show origin
Output: URL, HEAD branch, tracking...
git remote set-url <name> <url>
Description: Ganti URL remote.
Example:
git remote set-url origin git@github.com:user/repo.git
Output: URL diganti ke SSH

PUSH-PULL-FETCH

git push
Description: Push commit ke remote (branch saat ini).
Example:
git push
Output: Pushed to origin/main
git push -u origin <branch>
Description: Push branch baru & set upstream.
Example:
git push -u origin feature-login
Output: Branch 'feature-login' set up to track
git push --all
Description: Push semua branch ke remote.
Example:
git push --all origin
Output: Semua branch terpush
git push --tags
Description: Push semua tag ke remote.
Example:
git push --tags
Output: Tags terpush
git push --force
Description: Force push (timpa history remote — HATI-HATI).
Example:
git push --force
Output: ⚠️ Remote history ditimpa
git push --force-with-lease
Description: Force push lebih aman (cek dulu gak ada commit baru).
Example:
git push --force-with-lease
Output: Aman force push
git push origin --delete <branch>
Description: Hapus branch di remote.
Example:
git push origin --delete feature-lama
Output: Deleted remote branch
git fetch
Description: Ambil data remote tanpa merge.
Example:
git fetch
Output: Data terdownload
git fetch --prune
Description: Fetch + hapus tracking branch yang sudah dihapus di remote.
Example:
git fetch --prune
Output: Branch remote usang dihapus
git pull
Description: Fetch + merge ke branch saat ini.
Example:
git pull
Output: Updated
git pull --rebase
Description: Fetch + rebase (history linear).
Example:
git pull --rebase
Output: Rebased
git pull --ff-only
Description: Pull hanya jika bisa fast-forward (aman).
Example:
git pull --ff-only
Output: Fast-forward

TAG

git tag
Description: Lihat daftar tag.
Example:
git tag
Output: v1.0.0 v1.1.0
git tag <name>
Description: Buat lightweight tag.
Example:
git tag v1.0.0
Output: Tag v1.0.0
git tag -a <name> -m "msg"
Description: Buat annotated tag (disarankan).
Example:
git tag -a v2.0.0 -m "Release v2"
Output: Annotated tag v2.0.0
git tag -d <name>
Description: Hapus tag lokal.
Example:
git tag -d v1.0.0
Output: Deleted tag
git push origin <tag>
Description: Push 1 tag ke remote.
Example:
git push origin v1.0.0
Output: Tag terpush
git push origin --delete <tag>
Description: Hapus tag di remote.
Example:
git push origin --delete v1.0.0
Output: Remote tag deleted
git checkout <tag>
Description: Checkout ke tag (detached HEAD).
Example:
git checkout v1.0.0
Output: HEAD detached at v1.0.0

UNDO

git reset --soft <commit>
Description: Reset HEAD ke commit, simpan perubahan di staging.
Example:
git reset --soft HEAD~1
Output: Commit terakhir di-undo, file tetap staged
git reset --mixed <commit>
Description: Reset HEAD ke commit, simpan perubahan di working (default).
Example:
git reset HEAD~1
Output: Commit di-undo, file unstaged
git reset --hard <commit>
Description: Reset HEAD & buang semua perubahan (BAHAYA).
Example:
git reset --hard HEAD~1
Output: ⚠️ Perubahan hilang permanen
git revert <commit>
Description: Buat commit baru yang membatalkan commit tertentu (AMAN).
Example:
git revert a1b2c3d
Output: Commit revert dibuat
git revert --no-commit <commit>
Description: Revert tanpa auto-commit.
Example:
git revert --no-commit a1b2c3d
Output: Perubahan di staging
git reflog
Description: Lihat history HEAD (penyelamat commit hilang).
Example:
git reflog
Output: a1b2c3d HEAD@{0}: commit: ...
git checkout <commit> -- <file>
Description: Kembalikan 1 file ke versi commit tertentu.
Example:
git checkout a1b2c3d -- index.html
Output: File kembali

IGNORE

.gitignore
Description: File untuk mengabaikan file/folder dari Git.
Example:
node_modules/
.env
.DS_Store
Output: File diabaikan
git rm --cached <file>
Description: Hentikan tracking file (tetap ada di lokal).
Example:
git rm --cached file.log
Output: Untracked
git rm <file>
Description: Hapus file dari Git & lokal.
Example:
git rm file.log
Output: Deleted
git rm -r <folder>
Description: Hapus folder dari Git & lokal.
Example:
git rm -r old-folder
Output: Folder deleted
git check-ignore <file>
Description: Cek apakah file diabaikan .gitignore.
Example:
git check-ignore node_modules/
Output: node_modules/

GITHUB-CLI

gh auth login
Description: Login ke GitHub CLI.
Example:
gh auth login
Output: Authenticated
gh repo create <name>
Description: Buat repo baru di GitHub.
Example:
gh repo create my-project --public
Output: Repo created
gh repo clone <user/repo>
Description: Clone repo via GitHub CLI.
Example:
gh repo clone user/repo
Output: Cloned
gh repo view
Description: Buka repo di browser.
Example:
gh repo view --web
Output: Browser terbuka
gh pr create
Description: Buat Pull Request.
Example:
gh pr create --title "feat: login" --body "..."
Output: PR created
gh pr list
Description: Lihat daftar PR.
Example:
gh pr list
Output: #1 feat: login
gh pr checkout <n>
Description: Checkout branch dari PR.
Example:
gh pr checkout 1
Output: Switched
gh pr merge <n>
Description: Merge PR.
Example:
gh pr merge 1 --squash
Output: Merged
gh issue create
Description: Buat issue baru.
Example:
gh issue create --title "bug: ..." --body "..."
Output: Issue #1 created
gh issue list
Description: Lihat daftar issue.
Example:
gh issue list
Output: #1 bug: ...
gh release create <tag>
Description: Buat release.
Example:
gh release create v1.0.0 --title "v1.0.0"
Output: Release created
gh gist create <file>
Description: Buat gist dari file.
Example:
gh gist create script.js --public
Output: Gist created

CONVENTIONAL-COMMITS

feat:
Description: Fitur baru.
Example:
feat: add login page
Output: Minor version bump
fix:
Description: Perbaikan bug.
Example:
fix: resolve navbar overlap
Output: Patch version bump
chore:
Description: Tugas rutin / maintenance.
Example:
chore: update dependencies
Output: No version bump
docs:
Description: Perubahan dokumentasi.
Example:
docs: update README
Output: No version bump
style:
Description: Formatting, spasi, dll (tanpa ubah logika).
Example:
style: fix indentation
Output: No version bump
refactor:
Description: Refactor kode tanpa ubah fitur.
Example:
refactor: simplify auth logic
Output: No version bump
perf:
Description: Performa optimization.
Example:
perf: lazy load images
Output: Patch version bump
test:
Description: Tambah/perbaiki testing.
Example:
test: add unit test for login
Output: No version bump
build:
Description: Perubahan build system/dependencies.
Example:
build: upgrade webpack to v5
Output: No version bump
ci:
Description: Perubahan CI/CD.
Example:
ci: add GitHub Actions workflow
Output: No version bump
revert:
Description: Membatalkan commit sebelumnya.
Example:
revert: feat: add login page
Output: Patch version bump
BREAKING CHANGE:
Description: Perubahan yang tidak backward-compatible.
Example:
feat!: drop support for Node 14

BREAKING CHANGE: ...
Output: Major version bump