CINXE.COM
Git - Konfigurasi Git
<!DOCTYPE html> <html lang="id"> <head> <meta charset='utf-8'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Git - Konfigurasi Git</title> <link href="/favicon.ico" rel='shortcut icon' type='image/x-icon'> <link rel="stylesheet" href="/application.min.css"> <script src="/js/modernizr.js"></script> <script src="/js/modernize.js"></script> </head> <body id="documentation"> <div class="inner"> <header> <a href="/"><img src="/images/logo@2x.png" width="110" height="46" alt="Git" /></a> <span id="tagline"></span> <script type="text/javascript"> const taglines = [ "fast-version-control", "everything-is-local", "distributed-even-if-your-workflow-isnt", "local-branching-on-the-cheap", "distributed-is-the-new-centralized" ]; var tagline = taglines[Math.floor(Math.random() * taglines.length)]; document.getElementById('tagline').innerHTML = '--' + tagline; </script> <form id="search" action="/search/results"> <input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" /> </form> <div id="search-results"></div> </header> </div> <div class="inner"> <div id="content-wrapper"> <div tabindex="1" class="sidebar-btn"></div> <aside class="sidebar" id="sidebar"> <nav> <ul> <li> <a href="/about">About</a> <ul> </ul> </li> <li> <a href="/doc" class="active">Documentation</a> <ul class="expanded"> <li> <a href="/docs">Reference</a> </li> <li> <a href="/book" class="active">Book</a> </li> <li> <a href="/videos">Videos</a> </li> <li> <a href="/doc/ext">External Links</a> </li> </ul> </li> <li> <a href="/downloads">Downloads</a> <ul > <li> <a href="/downloads/guis">GUI Clients</a> </li> <li> <a href="/downloads/logos">Logos</a> </li> </ul> </li> <li> <a href="/community">Community</a> </li> </ul> <hr class="sidebar"> <p> This book is available in <a href="/book/en/v2/Customizing-Git-Git-Configuration">English</a>. </p> <p> Full translation available in <table> <tr><td><a href="/book/az/v2/Git%e2%80%99i-F%c9%99rdil%c9%99%c5%9fdirm%c9%99k-Git-Konfiqurasiyas%c4%b1">azərbaycan dili</a>,</td></tr> <tr><td><a href="/book/bg/v2/Git-%d0%bd%d0%b0-%d0%bd%d0%b8%d1%81%d0%ba%d0%be-%d0%bd%d0%b8%d0%b2%d0%be-Plumbing-%d0%b8-Porcelain-%d0%ba%d0%be%d0%bc%d0%b0%d0%bd%d0%b4%d0%b8">български език</a>,</td></tr> <tr><td><a href="/book/de/v2/Git-einrichten-Git-Konfiguration">Deutsch</a>,</td></tr> <tr><td><a href="/book/es/v2/Personalizaci%c3%b3n-de-Git-Configuraci%c3%b3n-de-Git">Español</a>,</td></tr> <tr><td><a href="/book/fr/v2/Personnalisation-de-Git-Configuration-de-Git">Français</a>,</td></tr> <tr><td><a href="/book/gr">Ελληνικά</a>,</td></tr> <tr><td><a href="/book/ja/v2/Git-%e3%81%ae%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%9e%e3%82%a4%e3%82%ba-Git-%e3%81%ae%e8%a8%ad%e5%ae%9a">日本語</a>,</td></tr> <tr><td><a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-Git-%ec%84%a4%ec%a0%95%ed%95%98%ea%b8%b0">한국어</a>,</td></tr> <tr><td><a href="/book/nl/v2/Git-aanpassen-Git-configuratie">Nederlands</a>,</td></tr> <tr><td><a href="/book/ru/v2/%d0%9d%d0%b0%d1%81%d1%82%d1%80%d0%be%d0%b9%d0%ba%d0%b0-Git-%d0%9a%d0%be%d0%bd%d1%84%d0%b8%d0%b3%d1%83%d1%80%d0%b0%d1%86%d0%b8%d1%8f-Git">Русский</a>,</td></tr> <tr><td><a href="/book/sl/v2/Prilagoditev-Gita-Konfiguracija-Git">Slovenščina</a>,</td></tr> <tr><td><a href="/book/tl/v2/Pag-aangkop-sa-Sariling-Pangangailagan-ng-Git-Kompigurasyon-ng-Git">Tagalog</a>,</td></tr> <tr><td><a href="/book/uk/v2/%d0%9d%d0%b0%d0%bb%d0%b0%d1%88%d1%82%d1%83%d0%b2%d0%b0%d0%bd%d0%bd%d1%8f-Git-%d0%9a%d0%be%d0%bd%d1%84%d1%96%d0%b3%d1%83%d1%80%d0%b0%d1%86%d1%96%d1%8f-Git">Українська</a></td></tr> <tr><td><a href="/book/zh/v2/%e8%87%aa%e5%ae%9a%e4%b9%89-Git-%e9%85%8d%e7%bd%ae-Git">简体中文</a>,</td></tr> </table> </p> <p> Partial translations available in <table> <tr><td><a href="/book/cs/v2/Customizing-Git-Git-Configuration">Čeština</a>,</td></tr> <tr><td><a href="/book/mk/v2/%d0%9f%d0%b5%d1%80%d1%81%d0%be%d0%bd%d0%b0%d0%bb%d0%b8%d0%b7%d0%b0%d1%86%d0%b8%d1%98%d0%b0-%d0%bd%d0%b0-Git-Git-Configuration">Македонски</a>,</td></tr> <tr><td><a href="/book/pl/v2/Dostosowywanie-Gita-Konfiguracja-Gita">Polski</a>,</td></tr> <tr><td><a href="/book/sr/v2/%d0%9f%d1%80%d0%b8%d0%bb%d0%b0%d0%b3%d0%be%d1%92%d0%b0%d0%b2%d0%b0%d1%9a%d0%b5-%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%b0-%d0%93%d0%b8%d1%82-%d0%9a%d0%be%d0%bd%d1%84%d0%b8%d0%b3%d1%83%d1%80%d0%b8%d1%81%d0%b0%d1%9a%d0%b5-%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%b0-%d0%93%d0%b8%d1%82">Српски</a>,</td></tr> <tr><td><a href="/book/uz/v2/Customizing-Git-Git-Configuration">Ўзбекча</a>,</td></tr> <tr><td><a href="/book/zh-tw/v2/Customizing-Git-Git-Configuration">繁體中文</a>,</td></tr> </table> </p> <p> Translations started for <table> <tr><td><a href="/book/be/v2/Customizing-Git-Git-Configuration">Беларуская</a>,</td></tr> <tr><td><a href="/book/fa/v2/Customizing-Git-Git-Configuration" dir="rtl">فارسی</a>,</td></tr> <tr><td><a href="/book/id/v2/Kostumisasi-Git-Konfigurasi-Git">Indonesian</a>,</td></tr> <tr><td><a href="/book/it/v2/Customizing-Git-Git-Configuration">Italiano</a>,</td></tr> <tr><td><a href="/book/ms/v2/Customizing-Git-Git-Configuration">Bahasa Melayu</a>,</td></tr> <tr><td><a href="/book/pt-br/v2/Customizing-Git-Git-Configuration">Português (Brasil)</a>,</td></tr> <tr><td><a href="/book/pt-pt/v2/Personalizar-o-Git-Git-Configuration">Português (Portugal)</a>,</td></tr> <tr><td><a href="/book/sv/v2/Customizing-Git-Git-Configuration">Svenska</a>,</td></tr> <tr><td><a href="/book/tr/v2/Git%e2%80%99i-%c3%96zelle%c5%9ftirmek-Git-Yap%c4%b1land%c4%b1rmas%c4%b1">Türkçe</a>.</td></tr> </table> </p> <hr class="sidebar"/> <p> The source of this book is <a href="https://github.com/progit/progit2-id">hosted on GitHub.</a></br> Patches, suggestions and comments are welcome. </p> </nav> </aside> <div id="content"> <div id="book-chapters"> <a class="dropdown-trigger" id="book-chapters-trigger" data-panel-id="chapters-dropdown" href="#">Chapters ▾</a> <div class='dropdown-panel' id='chapters-dropdown'> <div class='three-column'> <div class="column-left"> <ol class='book-toc'> <li class='chapter'> <h2>1. <a href="/book/id/v2/Memulai-Tentang-Version-Control">Memulai</a></h2> <ol> <li> 1.1 <a href="/book/id/v2/Memulai-Tentang-Version-Control">Tentang Version Control</a> </li> <li> 1.2 <a href="/book/id/v2/Memulai-Sejarah-Singkat-Git">Sejarah Singkat Git</a> </li> <li> 1.3 <a href="/book/id/v2/Memulai-Dasar-dasar-Git">Dasar-dasar Git</a> </li> <li> 1.4 <a href="/book/id/v2/Memulai-Command-Line">Command Line</a> </li> <li> 1.5 <a href="/book/id/v2/Memulai-Memasang-Git">Memasang Git</a> </li> <li> 1.6 <a href="/book/id/v2/Memulai-Pengaturan-Awal-Git">Pengaturan Awal Git</a> </li> <li> 1.7 <a href="/book/id/v2/Memulai-Mendapatkan-Bantuan">Mendapatkan Bantuan</a> </li> <li> 1.8 <a href="/book/id/v2/Memulai-Kesimpulan">Kesimpulan</a> </li> </ol> </li> <li class='chapter'> <h2>2. <a href="/book/id/v2/Git-Basics-Mendapatkan-Repository-Git">Git Basics</a></h2> <ol> <li> 2.1 <a href="/book/id/v2/Git-Basics-Mendapatkan-Repository-Git">Mendapatkan Repository Git</a> </li> <li> 2.2 <a href="/book/id/v2/Git-Basics-Recording-Changes-to-the-Repository">Recording Changes to the Repository</a> </li> <li> 2.3 <a href="/book/id/v2/Git-Basics-Viewing-the-Commit-History">Viewing the Commit History</a> </li> <li> 2.4 <a href="/book/id/v2/Git-Basics-Undoing-Things">Undoing Things</a> </li> <li> 2.5 <a href="/book/id/v2/Git-Basics-Working-with-Remotes">Working with Remotes</a> </li> <li> 2.6 <a href="/book/id/v2/Git-Basics-Tagging">Tagging</a> </li> <li> 2.7 <a href="/book/id/v2/Git-Basics-Alias-Git">Alias Git</a> </li> <li> 2.8 <a href="/book/id/v2/Git-Basics-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>3. <a href="/book/id/v2/Git-Branching-Branches-in-a-Nutshell">Git Branching</a></h2> <ol> <li> 3.1 <a href="/book/id/v2/Git-Branching-Branches-in-a-Nutshell">Branches in a Nutshell</a> </li> <li> 3.2 <a href="/book/id/v2/Git-Branching-Basic-Branching-and-Merging">Basic Branching and Merging</a> </li> <li> 3.3 <a href="/book/id/v2/Git-Branching-Branch-Management">Branch Management</a> </li> <li> 3.4 <a href="/book/id/v2/Git-Branching-Branching-Workflows">Branching Workflows</a> </li> <li> 3.5 <a href="/book/id/v2/Git-Branching-Remote-Branches">Remote Branches</a> </li> <li> 3.6 <a href="/book/id/v2/Git-Branching-Rebasing">Rebasing</a> </li> <li> 3.7 <a href="/book/id/v2/Git-Branching-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>4. <a href="/book/id/v2/Git-di-Server-Protokol">Git di Server</a></h2> <ol> <li> 4.1 <a href="/book/id/v2/Git-di-Server-Protokol">Protokol</a> </li> <li> 4.2 <a href="/book/id/v2/Git-di-Server-Getting-Git-on-a-Server">Getting Git on a Server</a> </li> <li> 4.3 <a href="/book/id/v2/Git-di-Server-Generating-Your-SSH-Public-Key">Generating Your SSH Public Key</a> </li> <li> 4.4 <a href="/book/id/v2/Git-di-Server-Setting-Up-the-Server">Setting Up the Server</a> </li> <li> 4.5 <a href="/book/id/v2/Git-di-Server-Git-Daemon">Git Daemon</a> </li> <li> 4.6 <a href="/book/id/v2/Git-di-Server-Smart-HTTP">Smart HTTP</a> </li> <li> 4.7 <a href="/book/id/v2/Git-di-Server-GitWeb">GitWeb</a> </li> <li> 4.8 <a href="/book/id/v2/Git-di-Server-GitLab">GitLab</a> </li> <li> 4.9 <a href="/book/id/v2/Git-di-Server-Third-Party-Hosted-Options">Third Party Hosted Options</a> </li> <li> 4.10 <a href="/book/id/v2/Git-di-Server-Ringkasan">Ringkasan</a> </li> </ol> </li> <li class='chapter'> <h2>5. <a href="/book/id/v2/Distributed-Git-Distributed-Workflows">Distributed Git</a></h2> <ol> <li> 5.1 <a href="/book/id/v2/Distributed-Git-Distributed-Workflows">Distributed Workflows</a> </li> <li> 5.2 <a href="/book/id/v2/Distributed-Git-Contributing-to-a-Project">Contributing to a Project</a> </li> <li> 5.3 <a href="/book/id/v2/Distributed-Git-Maintaining-a-Project">Maintaining a Project</a> </li> <li> 5.4 <a href="/book/id/v2/Distributed-Git-Summary">Summary</a> </li> </ol> </li> </ol> </div> <div class='column-middle'> <ol class='book-toc'> <li class='chapter'> <h2>6. <a href="/book/id/v2/GitHub-Pengaturan-dan-Konfigurasi-Akun">GitHub</a></h2> <ol> <li> 6.1 <a href="/book/id/v2/GitHub-Pengaturan-dan-Konfigurasi-Akun">Pengaturan dan Konfigurasi Akun</a> </li> <li> 6.2 <a href="/book/id/v2/GitHub-Contributing-to-a-Project">Contributing to a Project</a> </li> <li> 6.3 <a href="/book/id/v2/GitHub-Maintaining-a-Project">Maintaining a Project</a> </li> <li> 6.4 <a href="/book/id/v2/GitHub-Mengelola-Organization">Mengelola Organization</a> </li> <li> 6.5 <a href="/book/id/v2/GitHub-Scripting-GitHub">Scripting GitHub</a> </li> <li> 6.6 <a href="/book/id/v2/GitHub-Ringkasan">Ringkasan</a> </li> </ol> </li> <li class='chapter'> <h2>7. <a href="/book/id/v2/Git-Tools-Revision-Selection">Git Tools</a></h2> <ol> <li> 7.1 <a href="/book/id/v2/Git-Tools-Revision-Selection">Revision Selection</a> </li> <li> 7.2 <a href="/book/id/v2/Git-Tools-Interactive-Staging">Interactive Staging</a> </li> <li> 7.3 <a href="/book/id/v2/Git-Tools-Stashing-and-Cleaning">Stashing and Cleaning</a> </li> <li> 7.4 <a href="/book/id/v2/Git-Tools-Signing-Your-Work">Signing Your Work</a> </li> <li> 7.5 <a href="/book/id/v2/Git-Tools-Searching">Searching</a> </li> <li> 7.6 <a href="/book/id/v2/Git-Tools-Rewriting-History">Rewriting History</a> </li> <li> 7.7 <a href="/book/id/v2/Git-Tools-Reset-Demystified">Reset Demystified</a> </li> <li> 7.8 <a href="/book/id/v2/Git-Tools-Advanced-Merging">Advanced Merging</a> </li> <li> 7.9 <a href="/book/id/v2/Git-Tools-Rerere">Rerere</a> </li> <li> 7.10 <a href="/book/id/v2/Git-Tools-Debugging-with-Git">Debugging with Git</a> </li> <li> 7.11 <a href="/book/id/v2/Git-Tools-Submodules">Submodules</a> </li> <li> 7.12 <a href="/book/id/v2/Git-Tools-Bundling">Bundling</a> </li> <li> 7.13 <a href="/book/id/v2/Git-Tools-Replace">Replace</a> </li> <li> 7.14 <a href="/book/id/v2/Git-Tools-Credential-Storage">Credential Storage</a> </li> <li> 7.15 <a href="/book/id/v2/Git-Tools-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>8. <a href="/book/id/v2/Kostumisasi-Git-Konfigurasi-Git">Kostumisasi Git</a></h2> <ol> <li> 8.1 <a href="/book/id/v2/Kostumisasi-Git-Konfigurasi-Git" class="active">Konfigurasi Git</a> </li> <li> 8.2 <a href="/book/id/v2/Kostumisasi-Git-Git-Attributes">Git Attributes</a> </li> <li> 8.3 <a href="/book/id/v2/Kostumisasi-Git-Git-Hooks">Git Hooks</a> </li> <li> 8.4 <a href="/book/id/v2/Kostumisasi-Git-An-Example-Git-Enforced-Policy">An Example Git-Enforced Policy</a> </li> <li> 8.5 <a href="/book/id/v2/Kostumisasi-Git-Ringkasan">Ringkasan</a> </li> </ol> </li> <li class='chapter'> <h2>9. <a href="/book/id/v2/Git-and-Other-Systems-Git-as-a-Client">Git and Other Systems</a></h2> <ol> <li> 9.1 <a href="/book/id/v2/Git-and-Other-Systems-Git-as-a-Client">Git as a Client</a> </li> <li> 9.2 <a href="/book/id/v2/Git-and-Other-Systems-Migrating-to-Git">Migrating to Git</a> </li> <li> 9.3 <a href="/book/id/v2/Git-and-Other-Systems-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>10. <a href="/book/id/v2/Git-Internals-Plumbing-and-Porcelain">Git Internals</a></h2> <ol> <li> 10.1 <a href="/book/id/v2/Git-Internals-Plumbing-and-Porcelain">Plumbing and Porcelain</a> </li> <li> 10.2 <a href="/book/id/v2/Git-Internals-Git-Objects">Git Objects</a> </li> <li> 10.3 <a href="/book/id/v2/Git-Internals-Git-References">Git References</a> </li> <li> 10.4 <a href="/book/id/v2/Git-Internals-Packfiles">Packfiles</a> </li> <li> 10.5 <a href="/book/id/v2/Git-Internals-The-Refspec">The Refspec</a> </li> <li> 10.6 <a href="/book/id/v2/Git-Internals-Transfer-Protocols">Transfer Protocols</a> </li> <li> 10.7 <a href="/book/id/v2/Git-Internals-Maintenance-and-Data-Recovery">Maintenance and Data Recovery</a> </li> <li> 10.8 <a href="/book/id/v2/Git-Internals-Environment-Variables">Environment Variables</a> </li> <li> 10.9 <a href="/book/id/v2/Git-Internals-Summary">Summary</a> </li> </ol> </li> </ol> </div> <div class='column-right'> <ol class='book-toc'> <li class='chapter'> <h2>A1. <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Graphical-Interfaces">Appendix A: Git in Other Environments</a></h2> <ol> <li> A1.1 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Graphical-Interfaces">Graphical Interfaces</a> </li> <li> A1.2 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Visual-Studio">Git in Visual Studio</a> </li> <li> A1.3 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Eclipse">Git in Eclipse</a> </li> <li> A1.4 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Bash">Git in Bash</a> </li> <li> A1.5 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Zsh">Git in Zsh</a> </li> <li> A1.6 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Git-in-Powershell">Git in Powershell</a> </li> <li> A1.7 <a href="/book/id/v2/Appendix-A:-Git-in-Other-Environments-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>A2. <a href="/book/id/v2/Appendix-B:-Embedding-Git-in-your-Applications-Command-line-Git">Appendix B: Embedding Git in your Applications</a></h2> <ol> <li> A2.1 <a href="/book/id/v2/Appendix-B:-Embedding-Git-in-your-Applications-Command-line-Git">Command-line Git</a> </li> <li> A2.2 <a href="/book/id/v2/Appendix-B:-Embedding-Git-in-your-Applications-Libgit2">Libgit2</a> </li> <li> A2.3 <a href="/book/id/v2/Appendix-B:-Embedding-Git-in-your-Applications-JGit">JGit</a> </li> </ol> </li> <li class='chapter'> <h2>A3. <a href="/book/id/v2/Appendix-C:-Git-Commands-Setup-and-Config">Appendix C: Git Commands</a></h2> <ol> <li> A3.1 <a href="/book/id/v2/Appendix-C:-Git-Commands-Setup-and-Config">Setup and Config</a> </li> <li> A3.2 <a href="/book/id/v2/Appendix-C:-Git-Commands-Getting-and-Creating-Projects">Getting and Creating Projects</a> </li> <li> A3.3 <a href="/book/id/v2/Appendix-C:-Git-Commands-Basic-Snapshotting">Basic Snapshotting</a> </li> <li> A3.4 <a href="/book/id/v2/Appendix-C:-Git-Commands-Branching-and-Merging">Branching and Merging</a> </li> <li> A3.5 <a href="/book/id/v2/Appendix-C:-Git-Commands-Sharing-and-Updating-Projects">Sharing and Updating Projects</a> </li> <li> A3.6 <a href="/book/id/v2/Appendix-C:-Git-Commands-Inspection-and-Comparison">Inspection and Comparison</a> </li> <li> A3.7 <a href="/book/id/v2/Appendix-C:-Git-Commands-Debugging">Debugging</a> </li> <li> A3.8 <a href="/book/id/v2/Appendix-C:-Git-Commands-Patching">Patching</a> </li> <li> A3.9 <a href="/book/id/v2/Appendix-C:-Git-Commands-Email">Email</a> </li> <li> A3.10 <a href="/book/id/v2/Appendix-C:-Git-Commands-External-Systems">External Systems</a> </li> <li> A3.11 <a href="/book/id/v2/Appendix-C:-Git-Commands-Administration">Administration</a> </li> <li> A3.12 <a href="/book/id/v2/Appendix-C:-Git-Commands-Plumbing-Commands">Plumbing Commands</a> </li> </ol> </li> </ol> </div> </div> </div> <span class="light" id="edition"> 2nd Edition </span> </div> <div id="main" data-pagefind-filter="category:book" data-pagefind-meta="category:Book" data-pagefind-weight="0.05" data-pagefind-body class="book edition2"> <h1>8.1 Kostumisasi Git - Konfigurasi Git</h1> <div> <p>Sejauh ini, kita sudah membahas dasar-dasar bagaimana Git bekerja dan bagaimana menggunakannya, kita juga sudah memperkenalkan beberapa peralatan yang disediakan Git untuk membantu Anda menggunakannya dengan mudah dan efektif. Pada bab ini, kita akan melihat bagaimana Anda bisa membuat Git bekerja dengan kostumisasi, sambil memperkenalkan beberapa pengaturan konfigurasi penting dan sistem hook. Dengan peralatan-peralatan tersebut, akan memudahkan untuk membuat Git bekerja sesuai dengan yang Anda inginkan, perusahaan Anda, atau kebutuhan kelompok Anda.</p> <h2 id="_git_config">Konfigurasi Git</h2> <div class="paragraph"> <p> Sebagaimana telah Anda lihat secara singkat di <a href="/book/id/v2/ch00/_getting_started">Memulai</a>, Anda bisa menentukan pengaturan konfigurasi Git dengan perintah <code>git config</code>. Salah satu hal pertama yang harus Anda lakukan adalah menyiapkan nama dan alamat surel Anda:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com</code></pre> </div> </div> <div class="paragraph"> <p>Sekarang Anda akan mempelajari beberapa pilihan yang lebih menarik lagi yang bisa Anda gunakan untuk mengkostumisasi penggunaan Git Anda.</p> </div> <div class="paragraph"> <p>Pertama, tinjauan singkat: Git menggunakan bermacam-macam konfigurasi berkas untuk menentukan perilaku non-bawaan yang Anda inginkan. Tempat pertama Git mencari nilai-nilai tersebut adalah di berkas <code>/etc/gitconfig</code>, yang berisi nilai-nilai untuk setiap pengguna di sistem dan semua repositori-repositori mereka. Jika Anda memberikan pilihan <code>--system</code> ke <code>git config</code>, maka pilihan tersebut akan membaca dan menulis dari berkas ini secara khusus.</p> </div> <div class="paragraph"> <p>Tempat selanjutnya yang akan dilihat oleh Git adalah berkas <code>~/.gitconfig</code> (atau <code>~/.config/git/config</code>), yang khusus untuk setiap pengguna. Anda bisa membuat Git membaca dan menulis pada berkas ini dengan memberikan pilihan <code>--global</code>.</p> </div> <div class="paragraph"> <p>Akhirnya, Git akan mencari nilai-nilai konfigurasi di dalam berkas konfigurasi yang berada di direktori Git (<code>.git/config</code>) untuk repositori apapun yang sedang Anda gunakan. Nilai-nilai tersebut hanya untuk satu repositori tersebut.</p> </div> <div class="paragraph"> <p>Tiap-tiap “levels” tersebut (sistem, global, lokal) menulis ulang nilai-nilai pada level sebelumnya, jadi nilai-nilai di <code>.git/config</code> sebagai contohnya akan mengganti nilai-nilai yang ada di <code>/etc/gitconfig</code>.</p> </div> <div class="exampleblock"> <div class="content"> <div class="paragraph"> <p>Berkas konfigurasi Git merupakan teks biasa, jadi Anda juga bisa mengatur nilai-nilai tersebut dengan menyunting berkas secara manual dan memasukkan sintaks yang benar. Umumnya perintah <code>git config</code> lebih mudah dijalankan.</p> </div> </div> </div> <div class="sect3"> <h3 id="_konfigurasi_dasar_klien_git">Konfigurasi Dasar Klien Git</h3> <div class="paragraph"> <p>Pilihan-pilihan konfigurasi yang dikenali oleh Git terbagi ke dalam dua kategori: sisi-klien dan sisi-server. Pilihan-pilihan pada umumnya merupakan sisi-klien - yang mengkonfigurasi pilihan cara kerja personal Anda. Ada banyak sekali pilihan-pilihan konfigurasi yang sudah didukung, tetapi kebanyakan dari pilihan-pilihan tersebut hanya berguna pada kasus-kasus tertentu. Kita hanya akan membahas yang paling umum dan yang paling berguna disini. Jika Anda ingin melihat semua daftar pilihan-pilihan yang dikenali oleh versi Git Anda, Anda bisa menjalankan</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ man git-config</code></pre> </div> </div> <div class="paragraph"> <p>Perintah ini akan mencantumkan semua pilihan-pilihan yang tersedia dengan lebih mendetail. Anda juga bisa menemukan materi untuk rujukan ini di <a href="http://git-scm.com/docs/git-config.html" class="bare">http://git-scm.com/docs/git-config.html</a>.</p> </div> <div class="sect4"> <h4 id="_core_editor"><code>core.editor</code></h4> <div class="paragraph"> <p> Secara default, Git menggunakan apapun yang sudah Anda atur sebagai default penyunting teks Anda (<code>$VISUAL</code> atau <code>$EDITOR</code>) jika tidak maka akan kembali menggunakan penyunting <code>vi</code> untuk membuat dan mengubah pesan commit dan tag. Untuk mengubah default tersebut menjadi sesuatu yang lain, Anda bisa menggunakan pengaturan <code>core.editor</code>:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.editor emacs</code></pre> </div> </div> <div class="paragraph"> <p>Sekarang, terlepas dari apapun yang dipasang sebagai shell default penyunting Anda, Git akan menggunakan Emacs untuk menyunting pesan-pesan Anda.</p> </div> </div> <div class="sect4"> <h4 id="_commit_template"><code>commit.template</code></h4> <div class="paragraph"> <p> Jika Anda memasang ini ke jalur berkas pada komputer Anda, Git akan menggunakan berkas tersebut sebagai pesan default ketika melakukan commit. Sebagai contoh, anggap saja Anda membuat sebuah templat berkas di <code>~/.gitmessage.txt</code> yang terlihat seperti ini:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code>subject line what happened [ticket: X]</code></pre> </div> </div> <div class="paragraph"> <p>Untuk meminta Git menggunakannya sebagai pesan default yang muncul pada penyunting Anda saat Anda menjalankan <code>git commit</code>, aturlah nilai konfigurasi <code>commit.template</code>:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global commit.template ~/.gitmessage.txt $ git commit</code></pre> </div> </div> <div class="paragraph"> <p>Maka, penyunting Anda akan terbuka seperti ini pada tempat pesan commit Anda ketika Anda melakukan commit:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code>subject line what happened [ticket: X] # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: lib/test.rb # ~ ~ ".git/COMMIT_EDITMSG" 14L, 297C</code></pre> </div> </div> <div class="paragraph"> <p>Jika tim Anda mempunyai aturan untuk pesan-commit, maka memasang templat untuk aturan tersebut pada sistem Anda dan mengkonfigurasi Git untuk menggunakannya secara default akan membantu untuk meningkatkan kemungkinan aturan tersebut diikuti secara teratur.</p> </div> </div> <div class="sect4"> <h4 id="_core_pager"><code>core.pager</code></h4> <div class="paragraph"> <p> Pengaturan ini menentukan pager yang mana yang digunakan ketika Git melakukan pages output seperti <code>log</code> dan <code>diff</code>. Anda bisa mengaturnya menjadi <code>more</code> atau ke pager favorit Anda (secara default, hal tersebut merupakan <code>less</code>), atau Anda bisa mematikannya dengan mangaturnya ke string kosong:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.pager ''</code></pre> </div> </div> <div class="paragraph"> <p>Jika Anda menjalankan perintah tersebut, Git akan menampilkan semua pesan tanpa perantara more atau less, tidak perduli seberapa panjang perintah tersebut.</p> </div> </div> <div class="sect4"> <h4 id="_user_signingkey"><code>user.signingkey</code></h4> <div class="paragraph"> <p> jika Anda membuat signed annotated tags (sebagaimana yang telah dibahas di <a href="/book/id/v2/ch00/_signing">Signing Your Work</a>), mengatur kunci signin GPG Anda menjadi sebuah pengaturan konfigurasi akan membuat segala sesuatu menjadi lebih mudah. Atur kunci ID Anda seperti contoh berikut:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global user.signingkey <gpg-key-id></code></pre> </div> </div> <div class="paragraph"> <p>Sekarang, Anda bisa menandai tag tanpa harus selalu menentukan kunci Anda dengan perintah <code>git tag</code>:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git tag -s <tag-name></code></pre> </div> </div> </div> <div class="sect4"> <h4 id="_core_excludesfile"><code>core.excludesfile</code></h4> <div class="paragraph"> <p> Anda bisa membuat pola pada berkas <code>.gitignore</code> proyek Anda agar Git tidak melihatnya sebagai berkas yang untracked atau coba untuk menampilkannya ketika Anda menjalankan <code>git add</code> pada berkas-berkas tersebut, sebagaimana telah dibahas di <a href="/book/id/v2/ch00/_ignoring">Ignoring Files</a>.</p> </div> <div class="paragraph"> <p>Tetapi adakalannya Anda ingin mengabaikan berkas-berkas tertentu untuk semua repositori yang sedang Anda gunakan. Jika komputer Anda menggunakan Mac OS X, mungkin Anda sudah terbiasa dengan berkas-berkas <code>.DS_Store</code>. Jika Anda lebih suka menggunakan penyunting Emacs atau Vim, Anda pasti tahu tentang berkas-berkas yang berakhir dengan tanda <code>~</code>.</p> </div> <div class="paragraph"> <p>Pengaturan ini membuat Anda bisa menulis sebuah berkas umum dari <code>.gitignore</code>. Jika Anda membuat sebuah berkas <code>~/.gitignore_global</code> dengan konten-konten berikut:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code>*~ .DS_Store</code></pre> </div> </div> <div class="paragraph"> <p>…dan Anda menjalankan perintah <code>git config --global core.excludesfile ~/.gitignore_global</code>, Git tidak akan pernah lagi mempermasalahkan berkas-berkas tersebut.</p> </div> </div> <div class="sect4"> <h4 id="_help_autocorrect"><code>help.autocorrect</code></h4> <div class="paragraph"> <p> Jika Anda salah menulis perintah, Anda akan melihat sesuatu seperti ini:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git chekcout master git: 'chekcout' is not a git command. See 'git --help'. Did you mean this? checkout</code></pre> </div> </div> <div class="paragraph"> <p>Git akan mencoba memahami apa yang Anda maksud, tetapi tetap akan menolak untuk melakukannya. Jika Anda mengatur <code>help.autocorrect</code> dengan angka 1, Git hanya akan menjalankan perintah ini untuk Anda:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git chekcout master WARNING: You called a Git command named 'chekcout', which does not exist. -Continuing under the assumption that you meant 'checkout' -in 0.1 seconds automatically...</code></pre> </div> </div> <div class="paragraph"> <p>Catat bahwa nilai “0.1 seconds”. <code>help.autocorrect</code> sebenarnya merupakan sebuah bilangan bulat yang mewakili sepersepuluh detik. Jadi jika Anda mengaturnya pada angka 50, Git akan memberikan anda waktu 5 detik untuk berubah pikiran sebelum melakukan perintah autocorrected (perbaikan secara otomatis).</p> </div> </div> </div> <div class="sect3"> <h3 id="_warna_warna_didalam_git">Warna-warna didalam Git</h3> <div class="paragraph"> <p> Git memberi dukungan penuh untuk pewarnaan terminal output, yang akan sangat membantu dalam memvisualisasikan penguraian perintah output secara cepat dan mudah. Beberapa pilihan bisa membantu Anda mengatur pewarnaan sesuai dengan keinginan Anda.</p> </div> <div class="sect4"> <h4 id="_color_ui"><code>color.ui</code></h4> <div class="paragraph"> <p>Git mewarnai hampir semua outputnya secara otomatis, jikan Anda tidak suka dengan pengaturan seperti ini ada opsi untuk mematikannya. Semua pewarnaan pada terminal output Git bisa dimatikan dengan menjalankan perintah berikut:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global color.ui false</code></pre> </div> </div> <div class="paragraph"> <p>The default setting is <code>auto</code>, which colors output when it’s going straight to a terminal, but omits the color-control codes when the output is redirected to a pipe or a file.</p> </div> <div class="paragraph"> <p>You can also set it to <code>always</code> to ignore the difference between terminals and pipes. You’ll rarely want this; in most scenarios, if you want color codes in your redirected output, you can instead pass a <code>--color</code> flag to the Git command to force it to use color codes. The default setting is almost always what you’ll want.</p> </div> </div> <div class="sect4"> <h4 id="_color"><code>color.*</code></h4> <div class="paragraph"> <p>If you want to be more specific about which commands are colored and how, Git provides verb-specific coloring settings. Each of these can be set to <code>true</code>, <code>false</code>, or <code>always</code>:</p> </div> <div class="literalblock"> <div class="content"> <pre>color.branch color.diff color.interactive color.status</pre> </div> </div> <div class="paragraph"> <p>In addition, each of these has subsettings you can use to set specific colors for parts of the output, if you want to override each color. For example, to set the meta information in your diff output to blue foreground, black background, and bold text, you can run</p> </div> <div class="literalblock"> <div class="content"> <pre>$ git config --global color.diff.meta "blue black bold"</pre> </div> </div> <div class="paragraph"> <p>You can set the color to any of the following values: <code>normal</code>, <code>black</code>, <code>red</code>, <code>green</code>, <code>yellow</code>, <code>blue</code>, <code>magenta</code>, <code>cyan</code>, or <code>white</code>. If you want an attribute like bold in the previous example, you can choose from <code>bold</code>, <code>dim</code>, <code>ul</code> (underline), <code>blink</code>, and <code>reverse</code> (swap foreground and background).</p> </div> </div> </div> <div class="sect3"> <h3 id="_external_merge_tools">External Merge and Diff Tools</h3> <div class="paragraph"> <p> Although Git has an internal implementation of diff, which is what we’ve been showing in this book, you can set up an external tool instead. You can also set up a graphical merge-conflict-resolution tool instead of having to resolve conflicts manually. We’ll demonstrate setting up the Perforce Visual Merge Tool (P4Merge) to do your diffs and merge resolutions, because it’s a nice graphical tool and it’s free.</p> </div> <div class="paragraph"> <p>If you want to try this out, P4Merge works on all major platforms, so you should be able to do so. I’ll use path names in the examples that work on Mac and Linux systems; for Windows, you’ll have to change <code>/usr/local/bin</code> to an executable path in your environment.</p> </div> <div class="paragraph"> <p>To begin, download P4Merge from <a href="http://www.perforce.com/downloads/Perforce/" class="bare">http://www.perforce.com/downloads/Perforce/</a>. Next, you’ll set up external wrapper scripts to run your commands. I’ll use the Mac path for the executable; in other systems, it will be where your <code>p4merge</code> binary is installed. Set up a merge wrapper script named <code>extMerge</code> that calls your binary with all the arguments provided:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ cat /usr/local/bin/extMerge #!/bin/sh /Applications/p4merge.app/Contents/MacOS/p4merge $*</code></pre> </div> </div> <div class="paragraph"> <p>The diff wrapper checks to make sure seven arguments are provided and passes two of them to your merge script. By default, Git passes the following arguments to the diff program:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code>path old-file old-hex old-mode new-file new-hex new-mode</code></pre> </div> </div> <div class="paragraph"> <p>Because you only want the <code>old-file</code> and <code>new-file</code> arguments, you use the wrapper script to pass the ones you need.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ cat /usr/local/bin/extDiff #!/bin/sh [ $# -eq 7 ] && /usr/local/bin/extMerge "$2" "$5"</code></pre> </div> </div> <div class="paragraph"> <p>You also need to make sure these tools are executable:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ sudo chmod +x /usr/local/bin/extMerge $ sudo chmod +x /usr/local/bin/extDiff</code></pre> </div> </div> <div class="paragraph"> <p>Now you can set up your config file to use your custom merge resolution and diff tools. This takes a number of custom settings: <code>merge.tool</code> to tell Git what strategy to use, <code>mergetool.<tool>.cmd</code> to specify how to run the command, <code>mergetool.<tool>.trustExitCode</code> to tell Git if the exit code of that program indicates a successful merge resolution or not, and <code>diff.external</code> to tell Git what command to run for diffs. So, you can either run four config commands</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global merge.tool extMerge $ git config --global mergetool.extMerge.cmd \ 'extMerge \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"' $ git config --global mergetool.extMerge.trustExitCode false $ git config --global diff.external extDiff</code></pre> </div> </div> <div class="paragraph"> <p>or you can edit your <code>~/.gitconfig</code> file to add these lines:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-ini" data-lang="ini">[merge] tool = extMerge [mergetool "extMerge"] cmd = extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" trustExitCode = false [diff] external = extDiff</code></pre> </div> </div> <div class="paragraph"> <p>After all this is set, if you run diff commands such as this:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git diff 32d1776b1^ 32d1776b1</code></pre> </div> </div> <div class="paragraph"> <p>Instead of getting the diff output on the command line, Git fires up P4Merge, which looks something like this:</p> </div> <div class="imageblock"> <div class="content"> <img src="/book/id/v2/images/p4merge.png" alt="P4Merge."> </div> <div class="title">Figure 143. P4Merge.</div> </div> <div class="paragraph"> <p>If you try to merge two branches and subsequently have merge conflicts, you can run the command <code>git mergetool</code>; it starts P4Merge to let you resolve the conflicts through that GUI tool.</p> </div> <div class="paragraph"> <p>The nice thing about this wrapper setup is that you can change your diff and merge tools easily. For example, to change your <code>extDiff</code> and <code>extMerge</code> tools to run the KDiff3 tool instead, all you have to do is edit your <code>extMerge</code> file:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ cat /usr/local/bin/extMerge #!/bin/sh /Applications/kdiff3.app/Contents/MacOS/kdiff3 $*</code></pre> </div> </div> <div class="paragraph"> <p>Now, Git will use the KDiff3 tool for diff viewing and merge conflict resolution.</p> </div> <div class="paragraph"> <p>Git comes preset to use a number of other merge-resolution tools without your having to set up the cmd configuration. To see a list of the tools it supports, try this:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git mergetool --tool-help 'git mergetool --tool=<tool>' may be set to one of the following: emerge gvimdiff gvimdiff2 opendiff p4merge vimdiff vimdiff2 The following tools are valid, but not currently available: araxis bc3 codecompare deltawalker diffmerge diffuse ecmerge kdiff3 meld tkdiff tortoisemerge xxdiff Some of the tools listed above only work in a windowed environment. If run in a terminal-only session, they will fail.</code></pre> </div> </div> <div class="paragraph"> <p>If you’re not interested in using KDiff3 for diff but rather want to use it just for merge resolution, and the kdiff3 command is in your path, then you can run</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global merge.tool kdiff3</code></pre> </div> </div> <div class="paragraph"> <p>If you run this instead of setting up the <code>extMerge</code> and <code>extDiff</code> files, Git will use KDiff3 for merge resolution and the normal Git diff tool for diffs.</p> </div> </div> <div class="sect3"> <h3 id="_formatting_and_whitespace">Formatting and Whitespace</h3> <div class="paragraph"> <p> Formatting and whitespace issues are some of the more frustrating and subtle problems that many developers encounter when collaborating, especially cross-platform. It’s very easy for patches or other collaborated work to introduce subtle whitespace changes because editors silently introduce them, and if your files ever touch a Windows system, their line endings might be replaced. Git has a few configuration options to help with these issues.</p> </div> <div class="sect4"> <h4 id="_core_autocrlf"><code>core.autocrlf</code></h4> <div class="paragraph"> <p> If you’re programming on Windows and working with people who are not (or vice-versa), you’ll probably run into line-ending issues at some point. This is because Windows uses both a carriage-return character and a linefeed character for newlines in its files, whereas Mac and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work; many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key.</p> </div> <div class="paragraph"> <p>Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the <code>core.autocrlf</code> setting. If you’re on a Windows machine, set it to <code>true</code> – this converts LF endings into CRLF when you check out code:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.autocrlf true</code></pre> </div> </div> <div class="paragraph"> <p>If you’re on a Linux or Mac system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting <code>core.autocrlf</code> to input:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.autocrlf input</code></pre> </div> </div> <div class="paragraph"> <p>This setup should leave you with CRLF endings in Windows checkouts, but LF endings on Mac and Linux systems and in the repository.</p> </div> <div class="paragraph"> <p>If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to <code>false</code>:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.autocrlf false</code></pre> </div> </div> </div> <div class="sect4"> <h4 id="_core_whitespace"><code>core.whitespace</code></h4> <div class="paragraph"> <p>Git comes preset to detect and fix some whitespace issues. It can look for six primary whitespace issues – three are enabled by default and can be turned off, and three are disabled by default but can be activated.</p> </div> <div class="paragraph"> <p>The ones that are turned on by default are <code>blank-at-eol</code>, which looks for spaces at the end of a line; <code>blank-at-eof</code>, which notices blank lines at the end of a file; and <code>space-before-tab</code>, which looks for spaces before tabs at the beginning of a line.</p> </div> <div class="paragraph"> <p>The three that are disabled by default but can be turned on are <code>indent-with-non-tab</code>, which looks for lines that begin with spaces instead of tabs (and is controlled by the <code>tabwidth</code> option); <code>tab-in-indent</code>, which watches for tabs in the indentation portion of a line; and <code>cr-at-eol</code>, which tells Git that carriage returns at the end of lines are OK.</p> </div> <div class="paragraph"> <p>You can tell Git which of these you want enabled by setting <code>core.whitespace</code> to the values you want on or off, separated by commas. You can disable settings by either leaving them out of the setting string or prepending a <code>-</code> in front of the value. For example, if you want all but <code>cr-at-eol</code> to be set, you can do this:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.whitespace \ trailing-space,space-before-tab,indent-with-non-tab</code></pre> </div> </div> <div class="paragraph"> <p>Git will detect these issues when you run a <code>git diff</code> command and try to color them so you can possibly fix them before you commit. It will also use these values to help you when you apply patches with <code>git apply</code>. When you’re applying patches, you can ask Git to warn you if it’s applying patches with the specified whitespace issues:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git apply --whitespace=warn <patch></code></pre> </div> </div> <div class="paragraph"> <p>Or you can have Git try to automatically fix the issue before applying the patch:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git apply --whitespace=fix <patch></code></pre> </div> </div> <div class="paragraph"> <p>These options apply to the <code>git rebase</code> command as well. If you’ve committed whitespace issues but haven’t yet pushed upstream, you can run <code>git rebase --whitespace=fix</code> to have Git automatically fix whitespace issues as it’s rewriting the patches.</p> </div> </div> </div> <div class="sect3"> <h3 id="_server_configuration">Server Configuration</h3> <div class="paragraph"> <p>Not nearly as many configuration options are available for the server side of Git, but there are a few interesting ones you may want to take note of.</p> </div> <div class="sect4"> <h4 id="_receive_fsckobjects"><code>receive.fsckObjects</code></h4> <div class="paragraph"> <p>Git is capable of making sure every object received during a push still matches its SHA-1 checksum and points to valid objects. However, it doesn’t do this by default; it’s a fairly expensive operation, and might slow down the operation, especially on large repositories or pushes. If you want Git to check object consistency on every push, you can force it to do so by setting <code>receive.fsckObjects</code> to true:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --system receive.fsckObjects true</code></pre> </div> </div> <div class="paragraph"> <p>Now, Git will check the integrity of your repository before each push is accepted to make sure faulty (or malicious) clients aren’t introducing corrupt data.</p> </div> </div> <div class="sect4"> <h4 id="_receive_denynonfastforwards"><code>receive.denyNonFastForwards</code></h4> <div class="paragraph"> <p>If you rebase commits that you’ve already pushed and then try to push again, or otherwise try to push a commit to a remote branch that doesn’t contain the commit that the remote branch currently points to, you’ll be denied. This is generally good policy; but in the case of the rebase, you may determine that you know what you’re doing and can force-update the remote branch with a <code>-f</code> flag to your push command.</p> </div> <div class="paragraph"> <p>To tell Git to refuse force-pushes, set <code>receive.denyNonFastForwards</code>:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --system receive.denyNonFastForwards true</code></pre> </div> </div> <div class="paragraph"> <p>The other way you can do this is via server-side receive hooks, which we’ll cover in a bit. That approach lets you do more complex things like deny non-fast-forwards to a certain subset of users.</p> </div> </div> <div class="sect4"> <h4 id="_receive_denydeletes"><code>receive.denyDeletes</code></h4> <div class="paragraph"> <p>One of the workarounds to the <code>denyNonFastForwards</code> policy is for the user to delete the branch and then push it back up with the new reference. To avoid this, set <code>receive.denyDeletes</code> to true:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --system receive.denyDeletes true</code></pre> </div> </div> <div class="paragraph"> <p>This denies any deletion of branches or tags – no user can do it. To remove remote branches, you must remove the ref files from the server manually. There are also more interesting ways to do this on a per-user basis via ACLs, as you’ll learn in <a href="/book/id/v2/ch00/_an_example_git_enforced_policy">An Example Git-Enforced Policy</a>.</p> </div> </div> </div> <div id="nav"><a href="/book/id/v2/Git-Tools-Summary">prev</a> | <a href="/book/id/v2/Kostumisasi-Git-Git-Attributes">next</a></div> </div> </div> </div> </div> <footer> <div class="site-source"> <a href="/site">About this site</a><br> Patches, suggestions, and comments are welcome. </div> <div class="sfc-member"> Git is a member of <a href="/sfc">Software Freedom Conservancy</a> </div> </footer> <a href="#top" class="no-js scrollToTop" id="scrollToTop" data-label="Scroll to top"> <img src="/images/icons/chevron-up@2x.png" width="20" height="20" alt="scroll-to-top"/> </a> <script src="/js/jquery-1.7.1.min.js"></script> <script src="/js/jquery-ui-1.8.18.custom.min.js"></script> <script src="/js/jquery.defaultvalue.js"></script> <script src="/js/session.min.js"></script> <script src="/js/application.min.js"></script> </div> </body> </html>