Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Git — Setup & Konfigurasi ====== Halaman ini berisi konfigurasi dasar Git yang umum digunakan pada workstation atau server baru. ===== 1. Konfigurasi Global ===== Untuk melakukan setup sekaligus, edit konfigurasi global: <code bash> git config --global --edit </code> Contoh isi: <code ini> [user] name = Nama Anda email = email@example.com [init] defaultBranch = main [core] editor = code --wait autocrlf = input [alias] st = status co = checkout br = branch cm = commit last = log -1 HEAD </code> File konfigurasi global biasanya berada di: <code> ~/.gitconfig </code> Dapat diedit langsung menggunakan: <code bash> nano ~/.gitconfig </code> ===== 2. Konfigurasi Identitas ===== Identitas digunakan sebagai nama dan email pada setiap commit. <code bash> git config --global user.name "Nama Anda" git config --global user.email "email@example.com" </code> Verifikasi: <code bash> git config --global user.name git config --global user.email </code> ===== 3. Default Branch ===== Gunakan `main` sebagai default branch ketika membuat repository baru: <code bash> git config --global init.defaultBranch main </code> ===== 4. Credential ===== Periksa credential helper: <code bash> git config --global credential.helper </code> Credential dapat disimpan secara lokal dengan: <code bash> git config --global credential.helper store </code> > Hindari `credential.helper store` pada komputer bersama karena credential dapat tersimpan dalam bentuk plaintext. ===== 5. SSH untuk Git ===== Generate SSH key: <code bash> ssh-keygen -t ed25519 -C "email@example.com" </code> Jalankan SSH agent: <code bash> eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519 </code> Tampilkan public key: <code bash> cat ~/.ssh/id_ed25519.pub </code> Tambahkan public key tersebut ke layanan Git yang digunakan. Tes koneksi: <code bash> ssh -T git@github.com </code> ===== 6. Alias Git ===== Alias berguna untuk command yang sering digunakan: <code bash> git config --global alias.st status git config --global alias.co checkout git config --global alias.br branch git config --global alias.cm commit git config --global alias.last "log -1 HEAD" </code> Contoh penggunaan: <code bash> git st git br git cm -m "Update configuration" git last </code> ===== 7. Default Editor ===== Jika menggunakan Visual Studio Code: <code bash> git config --global core.editor "code --wait" </code> ===== 8. Line Ending ===== Untuk Linux: <code bash> git config --global core.autocrlf input </code> Untuk Windows: <code bash> git config --global core.autocrlf true </code> ===== 9. Konfigurasi Repository ===== Konfigurasi tanpa `--global` hanya berlaku pada repository tersebut. <code bash> git config user.name "Nama Berbeda" git config user.email "email@example.com" </code> Edit konfigurasi repository secara langsung: <code bash> git config --local --edit </code> File konfigurasi repository berada di: <code> .git/config </code> ===== 10. Level Konfigurasi Git ===== Git memiliki tiga level konfigurasi: ^ Level ^ File ^ Keterangan ^ | System | `/etc/gitconfig` | Berlaku untuk seluruh user | | Global | `~/.gitconfig` | Berlaku untuk user | | Local | `.git/config` | Hanya berlaku pada repository | Urutan konfigurasi yang lebih spesifik dapat menimpa konfigurasi yang lebih umum. ===== 11. Melihat Konfigurasi ===== Melihat konfigurasi global: <code bash> git config --global --list </code> Melihat konfigurasi repository: <code bash> git config --local --list </code> Melihat seluruh konfigurasi: <code bash> git config --list </code> Menampilkan sumber setiap konfigurasi: <code bash> git config --list --show-origin </code> Perintah `--show-origin` sangat berguna ketika terdapat konfigurasi yang tidak sesuai karena dapat menunjukkan file asal konfigurasi tersebut. ===== 12. Quick Setup ===== Untuk workstation atau server baru, konfigurasi minimum dapat dilakukan dengan: <code bash> git config --global user.name "Nama Anda" git config --global user.email "email@example.com" git config --global init.defaultBranch main git config --global core.editor "code --wait" </code> Atau langsung edit seluruh konfigurasi: <code bash> git config --global --edit </code> ===== 13. Troubleshooting Identity ===== Jika Git menampilkan: <code> Please tell me who you are. </code> atau: <code> Your name and email address were configured automatically. </code> Periksa konfigurasi: <code bash> git config --global user.name git config --global user.email </code> Jika belum ada, tambahkan konfigurasi: <code bash> git config --global user.name "Nama Anda" git config --global user.email "email@example.com" </code> Jika commit terakhir sudah dibuat dengan identitas yang salah: <code bash> git commit --amend --reset-author </code> ===== Referensi Cepat ===== ^ Kebutuhan ^ Command ^ | Edit konfigurasi global | `git config --global --edit` | | Edit konfigurasi repository | `git config --local --edit` | | Lihat konfigurasi | `git config --list` | | Lihat sumber konfigurasi | `git config --list --show-origin` | | Lihat username | `git config user.name` | | Lihat email | `git config user.email` | | Buat repository | `git init` | | Clone repository | `git clone <URL>` | | Cek status | `git status` | | Lihat branch | `git branch` | | Lihat remote | `git remote -v` | dev/git/setup.txt Last modified: 2026/09/16 15:48by ilyasa