04. Configuring Git's Global Settings

To check that Git is successfully installed, run the following command:

$ git --version
git version 2.2.1

The git command

The git command works with a variety of subcommands. Simply pass in these subcommands following git.

Let's start by setting global configuration parameters. Use the subcommand config to see a list of all the configurable parameters.

$ git config
usage: git config [options] Config file location --global use global config file --system use system config file --local use repository config file -f, --file <file> use given config file --blob <blob-id> read config from given blob object Action --get get value: name [value-regex] --get-all get all values: key [value-regex] --get-regexp get values for regexp: name-regex [value-regex] --get-urlmatch get value specific for the URL: section[.var] URL --replace-all replace all matching variables: name value [value_regex] --add add a new variable: name value --unset remove a variable: name [value-regex] --unset-all remove all matches: name [value-regex] --rename-section rename section: old-name new-name --remove-section remove a section: name -l, --list list all -e, --edit open an editor --get-color <slot> find the color configured: [default] --get-colorbool <slot> find the color setting: [stdout-is-tty] Type --bool value is "true" or "false" --int value is decimal number --bool-or-int value is --bool or --int --path value is a path (file or directory name) Other -z, --null terminate values with NUL byte --includes respect include directives on lookup

Configuration Files

Git configuration files will live in your /etc/gitconfig file. Those that are specific to the user will live in ~/.gitconfig. As we'll see shortly, we can edit the settings within ~/.gitconfig with the --globalflag.

$ cat ~/.gitconfig
[user] email = johndoe@johndoe.com name = John Doe

Setting your username and email

Set your username and email so that you may identify yourself and your computer with others.

$ git config --global user.name "john doe"
$ git config --global user.email johndoe@johndoe.com

Setting your default editor

When using Git, sometimes you'll need to enter a message to describe the changes you are making to the repository. When inputting these messages, you could have Git automatically open a text editor for you to type in.

By default, the text editor of choice is Vim, but in case you use emacs or another editor, you may set it with:

$ git config --global core.editor emacs

Setting a diff tool

The diff tool is used to resolve merge conflicts. For Vim users, we can use vimdiff.

$ git config --global merge.tool vimdiff

Turning on Color

To turn on color in the black and white terminal screen, use the following command:

$ git config --global color.ui true

This will make deletions red, and additions green.

Check your configurations

To check the list configuration edits you made, run:

$ git config --list

Finding Help

Git has many subcommands that it runs. For example, the subcommand add is used to track the files in your repository (we'll cover this in more detail later). To find any help (in case you get lost along the way), run git help with the subcommand.

$ git help add
NAME git-add - Add file contents to the index SYNOPSIS git add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p] [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--] [<pathspec>...] DESCRIPTION This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. It typically adds the current content of existing paths as a whole, but with some options it can also be used to add content with only part of the changes made to the working tree files applied, or remove paths that do not exist in the working tree anymore.

And don't forget git's man page!

$ git man

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

System Admin Handbook

Take your Linux skills to the next level! Try Linux & UNIX

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources