Git Configuration

init

  1. Set default branch

Since master is now considered politically incorrect, use the SVN format trunk.

~ $ git config --global init.defaultBranch trunk

All repositories now created will have the default branch set to trunk

core

  1. Set excludesfile

Keep the .gitignore file free from clobber and define files/directories never to include in SCM.

This includes but is not limited to:

  • IDE configuration files

  • Settings files

  • Generated sources, including such entries as

    • build directories

    • generated properties

  • hidden directories

Creating and commenting (.gitignore_global)

~ $ git config --global core.excludesFile '~/.gitignore_global'
~ $ printf '### Global ignores, applies to **ALL** repos ###

' >> $HOME/.gitignore_global

When using eclipse, a good first entry would be the ‘.project’ file:

~ $ printf ".project\n" >> $HOME/.gitignore_global

and since python is our primary language…

~ $ printf ".pydevproject\n" >> $HOME/.gitignore_global

not forgetting…

~ $ printf "build\n" >> $HOME/.gitignore_global

user

Rather than setting the user and email for each repository project, they can be set globally

  1. Set name

    ~ $ git config --global user.name "Your name"
    
  2. Set email

    ~ $ git config --global user.email yourname@example.com
    
  3. Set username

To ease access with scripted utilities and generall make life easy, an additional username entry can be used:

~ $ git config --global user.username gitusername

PGP

  1. Configure git PGP [github-version]

    As an added layer of security, git can be configured to cryptographically sign all commits, requiring PGP to be configured:

  2. List the keys, looking for the signing key [S]

    ~ $ gpg --list-secret-keys --keyid-format=long
    $HOME/.../.gnupg/pubring.kbx
    sec# ... <--
    ssb> ... [E] [expires: ...]
    ssb> ... [S] [expires: ...]
    ssb> ... [A] [expires: ...]
    
  3. Set gitconfig

    ~ $ git config --global user.signingkey ...
    
  4. Add to ‘.bashrc’

    ~ $ [ -f $HOME/.bashrc ] && printf "export GPG_TTY=\$(tty)\n" >> $RC
    

The -S flag can now be used to sign the commit.

And as a bonus - all commits will now have a lovely green tick next to them!