Difference between revisions of "Git settings"
(fixed name setting) |
(= didn't work for me...) |
||
Line 20: | Line 20: | ||
To avoid having to type in your github username and password every time you push something, | To avoid having to type in your github username and password every time you push something, | ||
− | <pre>git config --global credential.helper | + | <pre>git config --global credential.helper cache</pre> |
This will cache your details for 15 minutes so that you will not have to enter them again during that time. | This will cache your details for 15 minutes so that you will not have to enter them again during that time. | ||
To put a number of git command-line commands' output into colour, to make them more readable: | To put a number of git command-line commands' output into colour, to make them more readable: | ||
− | <pre>git config --global color.branch | + | <pre>git config --global color.branch auto |
− | git config --global color.diff | + | git config --global color.diff auto |
− | git config --global color.status | + | git config --global color.status auto |
− | git config --global color.ui | + | git config --global color.ui auto</pre> |
To set your preferred text editor (used for writing commit notes): | To set your preferred text editor (used for writing commit notes): | ||
− | <pre>git config --global core.editor | + | <pre>git config --global core.editor nano</pre> |
(change <tt>nano</tt> to the text editor of your choice) | (change <tt>nano</tt> to the text editor of your choice) | ||
Revision as of 10:54, 25 August 2012
This page currently lists a few git settings that I've found useful on my 'hack. These are from the perspective of a beginner with git who was trying to make it comfy to use. I'm hoping that an experienced git user may add anything else that's nifty or important.
You may also be interested in setting up command-line autocomplete for branch names and the like. If so, see Git autocomplete.
Levels of settings & how to change them
git has three levels of settings:
- system-wide, called "system"
- per-user, called "global"
- per-repo, called "local".
Settings can be viewed or set with the git config command. All the examples given below are per-user, which is probably the most useful on dreamhacks.
You can use git config --list to see the settings that you have at present.
Recommended settings
To add your username and email to commits:
git config --global user.name "???" git config --global user.email=???
where the ???s should be replaced with a username and email address. It is probably good practice to make this the same email address that you use for bugzilla.
To avoid having to type in your github username and password every time you push something,
git config --global credential.helper cache
This will cache your details for 15 minutes so that you will not have to enter them again during that time.
To put a number of git command-line commands' output into colour, to make them more readable:
git config --global color.branch auto git config --global color.diff auto git config --global color.status auto git config --global color.ui auto
To set your preferred text editor (used for writing commit notes):
git config --global core.editor nano
(change nano to the text editor of your choice)
Excluding files from git
You can tell git to ignore certain files and pay them no attention. For instance, I use vim as my main text editor, and vim creates .swp files all over the place to indicate when it has a file open. Whenever they appeared, git was warning me that these were "untracked files". To resolve this:
- Create a file in your home directory called .gitignore_global.
- In this file, specify the types of files to ignore. For example, mine simply says "*.swp".
- Then do
git config --global core.excludesfile=/dreamhack/home/????/.gitignore_global
, substituting your actual home directory for ????.