Harmonic Flow Framework

Harmonic Flow Blog

Git Basic Setup

Installation

First up, you should download and install Git for your preferred Operating System:
http://git-scm.com/downloads

First Time Setup

Now that you have Git on your system, you'll want to do a few things to customize your Git environment. You should have to do these things only once on any given computer; they'll stick around between upgrades.

Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:

  • /etc/gitconfig file: Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.
  • ~/.gitconfig or ~/.config/git/config file: Specific to your user. You can make Git read and write to this file specifically by passing the --global option.
  • config file in the Git directory (that is, .git/config) of whatever repository you’re currently using.

Each level overrides values in the previous level, so values in .git/config trump those in /etc/gitconfig.

Your Identiy

Your user name and email address is important to setup because every Git commit uses this information:

$ git config --global user.name "Your Name"
$ git config --global user.email youremail@example.org

Your Signing Key

Your signing key is useful if you want to do cryptographic signing. Read more about cryptography and signing here:
https://www.gnupg.org

$ git config --global user.signingkey 362B5F22

Your Editor

Configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git will use system default editor.

$ git config --global core.editor vim

Useful Git Aliases

If you don’t want to type the entire text of each of the Git commands, you can easily set up an alias for each command. Here are a couple of aliases I personally use:

$ git config --global alias.st status
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.up rebase
$ git config --global alias.ci "commit -s"
$ git config --global alias.lp "log -p"
$ git config --global alias.lod "log --oneline --decorate"
$ git config --global alias.lg "log --graph"
$ git config --global alias.lpo "log --pretty=oneline --abbrev-commit --graph --decorate --all"
$ git config --global alias.l1 "log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
$ git config --global alias.l2 "log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

Misc useful settings

Tells Git if the executable bit of files in the working tree is to be honored.

$ git config --global core.filemode true 

Controls which merge tool is used.

$ git config --global merge.tool vimdiff 

Controls which diff tool is used.

$ git config --global diff.tool vimdiff 

Mailing off a set of patches to a mailing list can be quite neatly done by git send-email. This setting is for that specifically. I'm personally using a neat program called msmtp for this. See http://msmtp.sourceforge.net/ for more information.

$ git-config --global sendemail.smtpserver /usr/bin/msmtp

Set it to always if you want all output not intended for machine consumption to use color, to true or auto if you want such output to use color when written to the terminal.

$ git config --global color.ui true

Enable the reflog.

$ git config --global core.logallrefupdates true

Checking your settings

Use the following command to check all your settings:

$ git config --list
user.name=Your Name
user.email=youremail@example.org
user.signingkey=362B5F22
alias.st=status
alias.co=checkout
...

Use the following command to check a specific setting:

$ git config user.name
Your Name

Recommended reading

The Git Reference docs explain everything about Git with really clear examples:
http://gitref.org/index.html

For the most direct and complete information on each command:
http://www.kernel.org/pub//software/scm/git/docs/

Amazing and simple tutorial that teaches you everything you need to know about using Git:
http://rogerdudler.github.com/git-guide/

Download the 'Git cheatsheet' and keep it handy:
http://rogerdudler.github.com/git-guide/files/git_cheat_sheet.pdf

See Git Basic Usage for a tutorial on how to use Git.

See How to submit a patch for a tutorial on how to submit a patch using Git.

Posted on Tue, 16 Feb 2016
Tags: git-basic-setup, git-tutorial



Comment On This Entry

Submit a comment on this entry.