CINXE.COM
Git - Git Configuration
<!DOCTYPE html> <html lang="pt-br"> <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 - Git Configuration</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-pt-br">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/pt-br/v2/Come%c3%a7ando-Sobre-Controle-de-Vers%c3%a3o">Começando</a></h2> <ol> <li> 1.1 <a href="/book/pt-br/v2/Come%c3%a7ando-Sobre-Controle-de-Vers%c3%a3o">Sobre Controle de Versão</a> </li> <li> 1.2 <a href="/book/pt-br/v2/Come%c3%a7ando-Uma-Breve-Hist%c3%b3ria-do-Git">Uma Breve História do Git</a> </li> <li> 1.3 <a href="/book/pt-br/v2/Come%c3%a7ando-O-B%c3%a1sico-do-Git">O Básico do Git</a> </li> <li> 1.4 <a href="/book/pt-br/v2/Come%c3%a7ando-A-Linha-de-Comando">A Linha de Comando</a> </li> <li> 1.5 <a href="/book/pt-br/v2/Come%c3%a7ando-Instalando-o-Git">Instalando o Git</a> </li> <li> 1.6 <a href="/book/pt-br/v2/Come%c3%a7ando-Configura%c3%a7%c3%a3o-Inicial-do-Git">Configuração Inicial do Git</a> </li> <li> 1.7 <a href="/book/pt-br/v2/Come%c3%a7ando-Pedindo-Ajuda">Pedindo Ajuda</a> </li> <li> 1.8 <a href="/book/pt-br/v2/Come%c3%a7ando-Sum%c3%a1rio">Sumário</a> </li> </ol> </li> <li class='chapter'> <h2>2. <a href="/book/pt-br/v2/Fundamentos-de-Git-Obtendo-um-Reposit%c3%b3rio-Git">Fundamentos de Git</a></h2> <ol> <li> 2.1 <a href="/book/pt-br/v2/Fundamentos-de-Git-Obtendo-um-Reposit%c3%b3rio-Git">Obtendo um Repositório Git</a> </li> <li> 2.2 <a href="/book/pt-br/v2/Fundamentos-de-Git-Gravando-Altera%c3%a7%c3%b5es-em-Seu-Reposit%c3%b3rio">Gravando Alterações em Seu Repositório</a> </li> <li> 2.3 <a href="/book/pt-br/v2/Fundamentos-de-Git-Vendo-o-hist%c3%b3rico-de-Commits">Vendo o histórico de Commits</a> </li> <li> 2.4 <a href="/book/pt-br/v2/Fundamentos-de-Git-Desfazendo-coisas">Desfazendo coisas</a> </li> <li> 2.5 <a href="/book/pt-br/v2/Fundamentos-de-Git-Trabalhando-de-Forma-Remota">Trabalhando de Forma Remota</a> </li> <li> 2.6 <a href="/book/pt-br/v2/Fundamentos-de-Git-Criando-Tags">Criando Tags</a> </li> <li> 2.7 <a href="/book/pt-br/v2/Fundamentos-de-Git-Apelidos-Git">Apelidos Git</a> </li> <li> 2.8 <a href="/book/pt-br/v2/Fundamentos-de-Git-Sum%c3%a1rio">Sumário</a> </li> </ol> </li> <li class='chapter'> <h2>3. <a href="/book/pt-br/v2/Branches-no-Git-Branches-em-poucas-palavras">Branches no Git</a></h2> <ol> <li> 3.1 <a href="/book/pt-br/v2/Branches-no-Git-Branches-em-poucas-palavras">Branches em poucas palavras</a> </li> <li> 3.2 <a href="/book/pt-br/v2/Branches-no-Git-O-b%c3%a1sico-de-Ramifica%c3%a7%c3%a3o-Branch-e-Mesclagem-Merge">O básico de Ramificação (Branch) e Mesclagem (Merge)</a> </li> <li> 3.3 <a href="/book/pt-br/v2/Branches-no-Git-Gest%c3%a3o-de-Branches">Gestão de Branches</a> </li> <li> 3.4 <a href="/book/pt-br/v2/Branches-no-Git-Fluxo-de-Branches">Fluxo de Branches</a> </li> <li> 3.5 <a href="/book/pt-br/v2/Branches-no-Git-Branches-remotos">Branches remotos</a> </li> <li> 3.6 <a href="/book/pt-br/v2/Branches-no-Git-Rebase">Rebase</a> </li> <li> 3.7 <a href="/book/pt-br/v2/Branches-no-Git-Sum%c3%a1rio">Sumário</a> </li> </ol> </li> <li class='chapter'> <h2>4. <a href="/book/pt-br/v2/Git-no-servidor-Os-Protocolos">Git no servidor</a></h2> <ol> <li> 4.1 <a href="/book/pt-br/v2/Git-no-servidor-Os-Protocolos">Os Protocolos</a> </li> <li> 4.2 <a href="/book/pt-br/v2/Git-no-servidor-Getting-Git-on-a-Server">Getting Git on a Server</a> </li> <li> 4.3 <a href="/book/pt-br/v2/Git-no-servidor-Gerando-Sua-Chave-P%c3%bablica-SSH">Gerando Sua Chave Pública SSH</a> </li> <li> 4.4 <a href="/book/pt-br/v2/Git-no-servidor-Setting-Up-the-Server">Setting Up the Server</a> </li> <li> 4.5 <a href="/book/pt-br/v2/Git-no-servidor-Git-Daemon">Git Daemon</a> </li> <li> 4.6 <a href="/book/pt-br/v2/Git-no-servidor-Smart-HTTP">Smart HTTP</a> </li> <li> 4.7 <a href="/book/pt-br/v2/Git-no-servidor-GitWeb">GitWeb</a> </li> <li> 4.8 <a href="/book/pt-br/v2/Git-no-servidor-GitLab">GitLab</a> </li> <li> 4.9 <a href="/book/pt-br/v2/Git-no-servidor-Third-Party-Hosted-Options">Third Party Hosted Options</a> </li> <li> 4.10 <a href="/book/pt-br/v2/Git-no-servidor-Sum%c3%a1rio">Sumário</a> </li> </ol> </li> <li class='chapter'> <h2>5. <a href="/book/pt-br/v2/Distributed-Git-Fluxos-de-Trabalho-Distribu%c3%addos">Distributed Git</a></h2> <ol> <li> 5.1 <a href="/book/pt-br/v2/Distributed-Git-Fluxos-de-Trabalho-Distribu%c3%addos">Fluxos de Trabalho Distribuídos</a> </li> <li> 5.2 <a href="/book/pt-br/v2/Distributed-Git-Contribuindo-com-um-Projeto">Contribuindo com um Projeto</a> </li> <li> 5.3 <a href="/book/pt-br/v2/Distributed-Git-Maintaining-a-Project">Maintaining a Project</a> </li> <li> 5.4 <a href="/book/pt-br/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/pt-br/v2/GitHub-Configurando-uma-conta">GitHub</a></h2> <ol> <li> 6.1 <a href="/book/pt-br/v2/GitHub-Configurando-uma-conta">Configurando uma conta</a> </li> <li> 6.2 <a href="/book/pt-br/v2/GitHub-Contribuindo-em-um-projeto">Contribuindo em um projeto</a> </li> <li> 6.3 <a href="/book/pt-br/v2/GitHub-Maintaining-a-Project">Maintaining a Project</a> </li> <li> 6.4 <a href="/book/pt-br/v2/GitHub-Managing-an-organization">Managing an organization</a> </li> <li> 6.5 <a href="/book/pt-br/v2/GitHub-Scripting-GitHub">Scripting GitHub</a> </li> <li> 6.6 <a href="/book/pt-br/v2/GitHub-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>7. <a href="/book/pt-br/v2/Git-Tools-Revision-Selection">Git Tools</a></h2> <ol> <li> 7.1 <a href="/book/pt-br/v2/Git-Tools-Revision-Selection">Revision Selection</a> </li> <li> 7.2 <a href="/book/pt-br/v2/Git-Tools-Interactive-Staging">Interactive Staging</a> </li> <li> 7.3 <a href="/book/pt-br/v2/Git-Tools-Stashing-and-Cleaning">Stashing and Cleaning</a> </li> <li> 7.4 <a href="/book/pt-br/v2/Git-Tools-Signing-Your-Work">Signing Your Work</a> </li> <li> 7.5 <a href="/book/pt-br/v2/Git-Tools-Searching">Searching</a> </li> <li> 7.6 <a href="/book/pt-br/v2/Git-Tools-Rewriting-History">Rewriting History</a> </li> <li> 7.7 <a href="/book/pt-br/v2/Git-Tools-Reset-Demystified">Reset Demystified</a> </li> <li> 7.8 <a href="/book/pt-br/v2/Git-Tools-Advanced-Merging">Advanced Merging</a> </li> <li> 7.9 <a href="/book/pt-br/v2/Git-Tools-Rerere">Rerere</a> </li> <li> 7.10 <a href="/book/pt-br/v2/Git-Tools-Debugging-with-Git">Debugging with Git</a> </li> <li> 7.11 <a href="/book/pt-br/v2/Git-Tools-Submodules">Submodules</a> </li> <li> 7.12 <a href="/book/pt-br/v2/Git-Tools-Bundling">Bundling</a> </li> <li> 7.13 <a href="/book/pt-br/v2/Git-Tools-Replace">Replace</a> </li> <li> 7.14 <a href="/book/pt-br/v2/Git-Tools-Credential-Storage">Credential Storage</a> </li> <li> 7.15 <a href="/book/pt-br/v2/Git-Tools-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>8. <a href="/book/pt-br/v2/Customizing-Git-Git-Configuration">Customizing Git</a></h2> <ol> <li> 8.1 <a href="/book/pt-br/v2/Customizing-Git-Git-Configuration" class="active">Git Configuration</a> </li> <li> 8.2 <a href="/book/pt-br/v2/Customizing-Git-Git-Attributes">Git Attributes</a> </li> <li> 8.3 <a href="/book/pt-br/v2/Customizing-Git-Git-Hooks">Git Hooks</a> </li> <li> 8.4 <a href="/book/pt-br/v2/Customizing-Git-An-Example-Git-Enforced-Policy">An Example Git-Enforced Policy</a> </li> <li> 8.5 <a href="/book/pt-br/v2/Customizing-Git-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>9. <a href="/book/pt-br/v2/Git-and-Other-Systems-Git-as-a-Client">Git and Other Systems</a></h2> <ol> <li> 9.1 <a href="/book/pt-br/v2/Git-and-Other-Systems-Git-as-a-Client">Git as a Client</a> </li> <li> 9.2 <a href="/book/pt-br/v2/Git-and-Other-Systems-Migrating-to-Git">Migrating to Git</a> </li> <li> 9.3 <a href="/book/pt-br/v2/Git-and-Other-Systems-Summary">Summary</a> </li> </ol> </li> <li class='chapter'> <h2>10. <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Encanamento-e-Porcelana">Funcionamento Interno do Git</a></h2> <ol> <li> 10.1 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Encanamento-e-Porcelana">Encanamento e Porcelana</a> </li> <li> 10.2 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Objetos-do-Git">Objetos do Git</a> </li> <li> 10.3 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Refer%c3%aancias-do-Git">Referências do Git</a> </li> <li> 10.4 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Packfiles">Packfiles</a> </li> <li> 10.5 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-The-Refspec">The Refspec</a> </li> <li> 10.6 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Transfer-Protocols">Transfer Protocols</a> </li> <li> 10.7 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Maintenance-and-Data-Recovery">Maintenance and Data Recovery</a> </li> <li> 10.8 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Vari%c3%a1veis-de-ambiente">Variáveis de ambiente</a> </li> <li> 10.9 <a href="/book/pt-br/v2/Funcionamento-Interno-do-Git-Sum%c3%a1rio">Sumário</a> </li> </ol> </li> </ol> </div> <div class='column-right'> <ol class='book-toc'> <li class='chapter'> <h2>A1. <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Graphical-Interfaces">Appendix A: Git em Outros Ambientes</a></h2> <ol> <li> A1.1 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Graphical-Interfaces">Graphical Interfaces</a> </li> <li> A1.2 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Git-in-Visual-Studio">Git in Visual Studio</a> </li> <li> A1.3 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Git-in-Eclipse">Git in Eclipse</a> </li> <li> A1.4 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Git-in-Bash">Git in Bash</a> </li> <li> A1.5 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Git-in-Zsh">Git in Zsh</a> </li> <li> A1.6 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Git-in-Powershell">Git in Powershell</a> </li> <li> A1.7 <a href="/book/pt-br/v2/Appendix-A:-Git-em-Outros-Ambientes-Resumo">Resumo</a> </li> </ol> </li> <li class='chapter'> <h2>A2. <a href="/book/pt-br/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/pt-br/v2/Appendix-B:-Embedding-Git-in-your-Applications-Command-line-Git">Command-line Git</a> </li> <li> A2.2 <a href="/book/pt-br/v2/Appendix-B:-Embedding-Git-in-your-Applications-Libgit2">Libgit2</a> </li> <li> A2.3 <a href="/book/pt-br/v2/Appendix-B:-Embedding-Git-in-your-Applications-JGit">JGit</a> </li> </ol> </li> <li class='chapter'> <h2>A3. <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Setup-and-Config">Appendix C: Git Commands</a></h2> <ol> <li> A3.1 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Setup-and-Config">Setup and Config</a> </li> <li> A3.2 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Getting-and-Creating-Projects">Getting and Creating Projects</a> </li> <li> A3.3 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Basic-Snapshotting">Basic Snapshotting</a> </li> <li> A3.4 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Branching-and-Merging">Branching and Merging</a> </li> <li> A3.5 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Sharing-and-Updating-Projects">Sharing and Updating Projects</a> </li> <li> A3.6 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Inspection-and-Comparison">Inspection and Comparison</a> </li> <li> A3.7 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Debugging">Debugging</a> </li> <li> A3.8 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Patching">Patching</a> </li> <li> A3.9 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Email">Email</a> </li> <li> A3.10 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-External-Systems">External Systems</a> </li> <li> A3.11 <a href="/book/pt-br/v2/Appendix-C:-Git-Commands-Administration">Administration</a> </li> <li> A3.12 <a href="/book/pt-br/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 Customizing Git - Git Configuration</h1> <div> <p>So far, we’ve covered the basics of how Git works and how to use it, and we’ve introduced a number of tools that Git provides to help you use it easily and efficiently. In this chapter, we’ll see how you can make Git operate in a more customized fashion, by introducing several important configuration settings and the hooks system. With these tools, it’s easy to get Git to work exactly the way you, your company, or your group needs it to.</p> <h2 id="r_git_config">Git Configuration</h2> <div class="paragraph"> <p> As you briefly saw in <a href="/book/pt-br/v2/ch00/ch01-introduction">[ch01-introduction]</a>, you can specify Git configuration settings with the <code>git config</code> command. One of the first things you did was set up your name and email address:</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>Now you’ll learn a few of the more interesting options that you can set in this manner to customize your Git usage.</p> </div> <div class="paragraph"> <p>First, a quick review: Git uses a series of configuration files to determine non-default behavior that you may want. The first place Git looks for these values is in an <code>/etc/gitconfig</code> file, which contains values for every user on the system and all of their repositories. If you pass the option <code>--system</code> to <code>git config</code>, it reads and writes from this file specifically.</p> </div> <div class="paragraph"> <p>The next place Git looks is the <code>~/.gitconfig</code> (or <code>~/.config/git/config</code>) file, which is specific to each user. You can make Git read and write to this file by passing the <code>--global</code> option.</p> </div> <div class="paragraph"> <p>Finally, Git looks for configuration values in the configuration file in the Git directory (<code>.git/config</code>) of whatever repository you’re currently using. These values are specific to that single repository.</p> </div> <div class="paragraph"> <p>Each of these “levels” (system, global, local) overwrites values in the previous level, so values in <code>.git/config</code> trump those in <code>/etc/gitconfig</code>, for instance.</p> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <div class="title">Note</div> </td> <td class="content"> <div class="paragraph"> <p>Git’s configuration files are plain-text, so you can also set these values by manually editing the file and inserting the correct syntax. It’s generally easier to run the <code>git config</code> command, though.</p> </div> </td> </tr> </table> </div> <div class="sect3"> <h3 id="_basic_client_configuration">Basic Client Configuration</h3> <div class="paragraph"> <p>The configuration options recognized by Git fall into two categories: client-side and server-side. The majority of the options are client-side – configuring your personal working preferences. Many, <em>many</em> configuration options are supported, but a large fraction of them are only useful in certain edge cases. We’ll only be covering the most common and most useful here. If you want to see a list of all the options your version of Git recognizes, you can run</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>This command lists all the available options in quite a bit of detail. You can also find this reference material at <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> By default, Git uses whatever you’ve set as your default text editor (<code>$VISUAL</code> or <code>$EDITOR</code>) or else falls back to the <code>vi</code> editor to create and edit your commit and tag messages. To change that default to something else, you can use the <code>core.editor</code> setting:</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>Now, no matter what is set as your default shell editor, Git will fire up Emacs to edit messages.</p> </div> </div> <div class="sect4"> <h4 id="_commit_template"><code>commit.template</code></h4> <div class="paragraph"> <p> If you set this to the path of a file on your system, Git will use that file as the default message when you commit. For instance, suppose you create a template file at <code>~/.gitmessage.txt</code> that looks like this:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-text" data-lang="text">subject line what happened [ticket: X]</code></pre> </div> </div> <div class="paragraph"> <p>To tell Git to use it as the default message that appears in your editor when you run <code>git commit</code>, set the <code>commit.template</code> configuration value:</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>Then, your editor will open to something like this for your placeholder commit message when you commit:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-text" data-lang="text">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>If your team has a commit-message policy, then putting a template for that policy on your system and configuring Git to use it by default can help increase the chance of that policy being followed regularly.</p> </div> </div> <div class="sect4"> <h4 id="_core_pager"><code>core.pager</code></h4> <div class="paragraph"> <p> This setting determines which pager is used when Git pages output such as <code>log</code> and <code>diff</code>. You can set it to <code>more</code> or to your favorite pager (by default, it’s <code>less</code>), or you can turn it off by setting it to a blank string:</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>If you run that, Git will page the entire output of all commands, no matter how long they are.</p> </div> </div> <div class="sect4"> <h4 id="_user_signingkey"><code>user.signingkey</code></h4> <div class="paragraph"> <p> If you’re making signed annotated tags (as discussed in <a href="/book/pt-br/v2/ch00/r_signing">Signing Your Work</a>), setting your GPG signing key as a configuration setting makes things easier. Set your key ID like so:</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>Now, you can sign tags without having to specify your key every time with the <code>git tag</code> command:</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> You can put patterns in your project’s <code>.gitignore</code> file to have Git not see them as untracked files or try to stage them when you run <code>git add</code> on them, as discussed in <a href="/book/pt-br/v2/ch00/r_ignoring">Ignorando Arquivos</a>.</p> </div> <div class="paragraph"> <p>But sometimes you want to ignore certain files for all repositories that you work with. If your computer is running Mac OS X, you’re probably familiar with <code>.DS_Store</code> files. If your preferred editor is Emacs or Vim, you know about filenames that end with a <code>~</code> or <code>.swp</code>.</p> </div> <div class="paragraph"> <p>This setting lets you write a kind of global <code>.gitignore</code> file. If you create a <code>~/.gitignore_global</code> file with these contents:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-ini" data-lang="ini">*~ .*.swp .DS_Store</code></pre> </div> </div> <div class="paragraph"> <p>…and you run <code>git config --global core.excludesfile ~/.gitignore_global</code>, Git will never again bother you about those files.</p> </div> </div> <div class="sect4"> <h4 id="_help_autocorrect"><code>help.autocorrect</code></h4> <div class="paragraph"> <p> If you mistype a command, it shows you something like this:</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 helpfully tries to figure out what you meant, but it still refuses to do it. If you set <code>help.autocorrect</code> to 1, Git will actually run this command for you:</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>Note that “0.1 seconds” business. <code>help.autocorrect</code> is actually an integer which represents tenths of a second. So if you set it to 50, Git will give you 5 seconds to change your mind before executing the autocorrected command.</p> </div> </div> </div> <div class="sect3"> <h3 id="_colors_in_git">Colors in Git</h3> <div class="paragraph"> <p> Git fully supports colored terminal output, which greatly aids in visually parsing command output quickly and easily. A number of options can help you set the coloring to your preference.</p> </div> <div class="sect4"> <h4 id="_color_ui"><code>color.ui</code></h4> <div class="paragraph"> <p>Git automatically colors most of its output, but there’s a master switch if you don’t like this behavior. To turn off all Git’s colored terminal output, do this:</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="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global color.diff.meta "blue black bold"</code></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="r_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. We’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, <a href="https://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools">download P4Merge from Perforce</a>. Next, you’ll set up external wrapper scripts to run your commands. We’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/pt-br/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 three 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 an option by prepending a <code>-</code> in front of its name, or use the default value by leaving it out of the setting string entirely. For example, if you want all but <code>space-before-tab</code> to be set, you can do this (with <code>trailing-space</code> being a short-hand to cover both <code>blank-at-eol</code> and <code>blank-at-eof</code>):</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,tab-in-indent,cr-at-eol</code></pre> </div> </div> <div class="paragraph"> <p>Or you can specify the customizing part only:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git config --global core.whitespace \ -space-before-tab,indent-with-non-tab,tab-in-indent,cr-at-eol</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/pt-br/v2/ch00/r_an_example_git_enforced_policy">An Example Git-Enforced Policy</a>.</p> </div> </div> </div> <div id="nav"><a href="/book/pt-br/v2/Git-Tools-Summary">prev</a> | <a href="/book/pt-br/v2/Customizing-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>