|
| 1 | +.. _configure-git: |
| 2 | + |
| 3 | +=============== |
| 4 | + Configure git |
| 5 | +=============== |
| 6 | + |
| 7 | +.. _git-config-basic: |
| 8 | + |
| 9 | +Overview |
| 10 | +======== |
| 11 | + |
| 12 | +Your personal git_ configurations are saved in the ``.gitconfig`` file in |
| 13 | +your home directory. |
| 14 | +Here is an example ``.gitconfig`` file:: |
| 15 | + |
| 16 | + [user] |
| 17 | + name = Your Name |
| 18 | + |
| 19 | + |
| 20 | + [alias] |
| 21 | + ci = commit -a |
| 22 | + co = checkout |
| 23 | + st = status -a |
| 24 | + stat = status -a |
| 25 | + br = branch |
| 26 | + wdiff = diff --color-words |
| 27 | + |
| 28 | + [core] |
| 29 | + editor = vim |
| 30 | + |
| 31 | + [merge] |
| 32 | + summary = true |
| 33 | + |
| 34 | +You can edit this file directly or you can use the ``git config --global`` |
| 35 | +command:: |
| 36 | + |
| 37 | + git config --global user.name "Your Name" |
| 38 | + git config --global user.email [email protected] |
| 39 | + git config --global alias.ci "commit -a" |
| 40 | + git config --global alias.co checkout |
| 41 | + git config --global alias.st "status -a" |
| 42 | + git config --global alias.stat "status -a" |
| 43 | + git config --global alias.br branch |
| 44 | + git config --global alias.wdiff "diff --color-words" |
| 45 | + git config --global core.editor vim |
| 46 | + git config --global merge.summary true |
| 47 | + |
| 48 | +To set up on another computer, you can copy your ``~/.gitconfig`` file, |
| 49 | +or run the commands above. |
| 50 | + |
| 51 | +In detail |
| 52 | +========= |
| 53 | + |
| 54 | +user.name and user.email |
| 55 | +------------------------ |
| 56 | + |
| 57 | +It is good practice to tell git_ who you are, for labeling any changes |
| 58 | +you make to the code. The simplest way to do this is from the command |
| 59 | +line:: |
| 60 | + |
| 61 | + git config --global user.name "Your Name" |
| 62 | + git config --global user.email [email protected] |
| 63 | + |
| 64 | +This will write the settings into your git configuration file, which |
| 65 | +should now contain a user section with your name and email:: |
| 66 | + |
| 67 | + [user] |
| 68 | + name = Your Name |
| 69 | + |
| 70 | + |
| 71 | +Of course you'll need to replace `` Your Name`` and `` [email protected]`` |
| 72 | +with your actual name and email address. |
| 73 | + |
| 74 | +Aliases |
| 75 | +------- |
| 76 | + |
| 77 | +You might well benefit from some aliases to common commands. |
| 78 | + |
| 79 | +For example, you might well want to be able to shorten ``git checkout`` |
| 80 | +to ``git co``. Or you may want to alias ``git diff --color-words`` |
| 81 | +(which gives a nicely formatted output of the diff) to ``git wdiff`` |
| 82 | + |
| 83 | +The following ``git config --global`` commands:: |
| 84 | + |
| 85 | + git config --global alias.ci "commit -a" |
| 86 | + git config --global alias.co checkout |
| 87 | + git config --global alias.st "status -a" |
| 88 | + git config --global alias.stat "status -a" |
| 89 | + git config --global alias.br branch |
| 90 | + git config --global alias.wdiff "diff --color-words" |
| 91 | + |
| 92 | +will create an ``alias`` section in your ``.gitconfig`` file with contents |
| 93 | +like this:: |
| 94 | + |
| 95 | + [alias] |
| 96 | + ci = commit -a |
| 97 | + co = checkout |
| 98 | + st = status -a |
| 99 | + stat = status -a |
| 100 | + br = branch |
| 101 | + wdiff = diff --color-words |
| 102 | + |
| 103 | +Editor |
| 104 | +------ |
| 105 | + |
| 106 | +You may also want to make sure that your editor of choice is used :: |
| 107 | + |
| 108 | + git config --global core.editor vim |
| 109 | + |
| 110 | +Merging |
| 111 | +------- |
| 112 | + |
| 113 | +To enforce summaries when doing merges (``~/.gitconfig`` file again):: |
| 114 | + |
| 115 | + [merge] |
| 116 | + log = true |
| 117 | + |
| 118 | +Or from the command line:: |
| 119 | + |
| 120 | + git config --global merge.log true |
| 121 | + |
| 122 | + |
| 123 | +.. include:: git_links.inc |
0 commit comments