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

Learn how teams work in Agile

Scrum: A Brief and Agile Introduction

Learn how teams work in Agile Try Productivity Tools

If you're looking to learn the elements of Agile development and Scrum, this is the book for you. This book has been reviewed by many, and sought after as a must-read for anyone who works in agile. The book is brief, with no anecdotes nor reiterations. Just pure content to help you graph what Scrum is in no time.

$ Check price
9.959.95Amazon 4.5 logo(568+ reviews)

More Productivity Tools resources

Take your Linux skills to the next level!

The Linux Command Line

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

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

$ Check price
39.9539.95Amazon 4.5 logo(274+ reviews)

More Linux & UNIX resources