Difference between revisions of "Git settings"

From Dreamwidth Notes
Jump to: navigation, search
(command for storing password for # seconds)
m (typo)
 
(7 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
You may also be interested in setting up command-line autocomplete for branch names and the like. If so, see [[Git autocomplete]].
 
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 =
+
= Settings levels & how to change them =
 
git has three levels of settings:  
 
git has three levels of settings:  
 
* system-wide, called "system"
 
* system-wide, called "system"
Line 14: Line 14:
  
 
= Recommended settings =
 
= Recommended settings =
 +
 +
== Username and email address ==
 +
 
To add your username and email to commits:
 
To add your username and email to commits:
 
<pre>git config --global user.name "???"
 
<pre>git config --global user.name "???"
 
git config --global user.email=???</pre>
 
git config --global user.email=???</pre>
where the <tt>???</tt>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.
+
where the <tt>???</tt>s should be replaced with a username and email address. If possible, this should be [http://dw-dev.dreamwidth.org/125137.html set to your Dreamwidth username and your <tt>username@dreamwidth.org</tt> email address].
 +
 
 +
== Credentials caching ==
  
 
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,
Line 24: Line 29:
  
 
If you want to limit this to five minutes (i.e. 300 seconds) instead use:
 
If you want to limit this to five minutes (i.e. 300 seconds) instead use:
<pre>git config credential.helper 'cache --timeout=300'</pre>.
+
<pre>git config --global credential.helper 'cache --timeout=300'</pre>
 
+
 
You can of course increase or decrease the number. Note that storing your password for a very long time may be ill-advised.
 
You can of course increase or decrease the number. Note that storing your password for a very long time may be ill-advised.
  
To put a number of git command-line commands' output into colour, to make them more readable:
+
== Colors ==
 +
 
 +
Many git commands can render their output in color, which can help make them more readable. To tell git to use color output for every command that supports it, use:
 +
 
 +
<pre>git config --global color.ui auto</pre>
 +
 
 +
If you don't want color output for every command, but only for a select few, you can set them individually, eg:
 +
 
 
<pre>git config --global color.branch auto
 
<pre>git config --global color.branch auto
 
git config --global color.diff auto
 
git config --global color.diff auto
git config --global color.status auto
+
git config --global color.status auto</pre>
git config --global color.ui auto</pre>
+
 
 +
If the default colors (mostly red and green) aren't a good fit for you, you can change them: see [http://shallowsky.com/blog/programming/gitcolors.html Configuring git colors] for detailed explanations and examples.
 +
 
 +
== Editor ==
  
 
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 nano</pre>
 
<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)
 +
 +
= Other useful settings =
 +
 +
You may find some of these settings useful to configure git to your personal liking.
 +
 +
== Default pager & pager settings ==
 +
 +
git uses the <tt>less</tt> command to show output a page at a time, and it does so with its own preferred set of options -- specifically, <tt>less -FRSX</tt> -- unless you configure it differently.
 +
 +
Some people don't like the <tt>-S</tt> option, which causes long lines to be "cut off" at the edge of the screen. (Note that you can always pan left and right with the left-arrow and right-arrow keys to see all of a long line, though). 
 +
 +
If you would rather have <tt>less</tt> "wrap" long lines like it usually does, this (admittedly awful-looking) pager configuration will make that happen:
 +
 +
<pre>git config --global core.pager 'less -+$LESS -FRX'</pre>
 +
 +
''(Behind the scenes, what this effectively ends up saying is "run <tt>less</tt>, but take away the options that git is setting, and add back the options <tt>FRX</tt>".)''
 +
  
 
= Excluding files from git =
 
= 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:
 
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 <tt>.gitignore_global</tt>.
 
* Create a file in your home directory called <tt>.gitignore_global</tt>.
 
* In this file, specify the types of files to ignore. For example, mine simply says "<tt>*.swp</tt>".
 
* In this file, specify the types of files to ignore. For example, mine simply says "<tt>*.swp</tt>".
* Then do <pre>git config --global core.excludesfile=/dreamhack/home/????/.gitignore_global</pre>, substituting your actual home directory for <tt>????</tt>.
+
* Then do <pre>git config --global core.excludesfile /dreamhack/home/????/.gitignore_global</pre>, substituting your actual home directory for <tt>????</tt>.
  
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Git]]
 
[[Category:Git]]

Latest revision as of 19:41, 30 April 2013

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.

Settings levels & 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

Username and email address

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. If possible, this should be set to your Dreamwidth username and your username@dreamwidth.org email address.

Credentials caching

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.

If you want to limit this to five minutes (i.e. 300 seconds) instead use:

git config --global credential.helper 'cache --timeout=300'

You can of course increase or decrease the number. Note that storing your password for a very long time may be ill-advised.

Colors

Many git commands can render their output in color, which can help make them more readable. To tell git to use color output for every command that supports it, use:

git config --global color.ui auto

If you don't want color output for every command, but only for a select few, you can set them individually, eg:

git config --global color.branch auto
git config --global color.diff auto
git config --global color.status auto

If the default colors (mostly red and green) aren't a good fit for you, you can change them: see Configuring git colors for detailed explanations and examples.

Editor

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)

Other useful settings

You may find some of these settings useful to configure git to your personal liking.

Default pager & pager settings

git uses the less command to show output a page at a time, and it does so with its own preferred set of options -- specifically, less -FRSX -- unless you configure it differently.

Some people don't like the -S option, which causes long lines to be "cut off" at the edge of the screen. (Note that you can always pan left and right with the left-arrow and right-arrow keys to see all of a long line, though).

If you would rather have less "wrap" long lines like it usually does, this (admittedly awful-looking) pager configuration will make that happen:

git config --global core.pager 'less -+$LESS -FRX'

(Behind the scenes, what this effectively ends up saying is "run less, but take away the options that git is setting, and add back the options FRX".)


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 ????.