Recent Changes - Search:

Basics

Languages

Tools

OS

Resources

PmWiki

pmwiki.org

edit SideBar

Git /

Configuring Git

Before you start using Git to track changes, it is best to define some general parameters for it.

First, the syntax. The form below allows you to define the value of one of git's property, in a global fashion (all the git repositories you start on this computer will share global properties).

git config --global "property" "value"

Using this syntax, I could, for example, define which user name I want associated with my repositories by typing:

git config --global "user.name" "Jean-Pierre Auclair" ```

So, which properties should be defined? I use the following:

user.name=Jean-Pierre Auclair
user.email=jn402157@dal.ca
core.autocrlf=input
core.editor=vi
color.ui=auto
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

To know what properties have been defined (ie get the above list), you can see them all with:

git config --list

Caching authentication for remote repos

Some remote repos will require authentication when trying to interact with them. When using SSH, this can be dealt with using an SSH key, but sometimes remote servers will disable SSH entirely, forcing you to use HTTPS instead. You can still get around entering your username and password every time by using the "git credential helper". You only need to enable it, then provide it with a duration for which to hold the cache, if you are not happy with the default of 15 minutes.

# Set git to use the credential memory cache
git config --global credential.helper cache
# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'

Autocompletion for the git prompt:

It is possible to have git auto-complete things like branch and remote names, or commands. The package to use for this is available at: https://github.com/git/git/tree/master/contrib/completion

And the git website gives the following instructions on how to use it (as of Feb. 8th, 2018):

If you use the Bash shell, Git comes with a nice auto-completion script you can enable. Download it directly from the Git source code at https://github.com/git/git/blob/master/contrib/completion/git-completion.bash. Copy this file to your home directory, and add this to your .bashrc file:

source ~/git-completion.bash

If you want to set up Git to automatically have Bash shell completion for all users, copy this script to the /opt/local/etc/bash_completion.d directory on Mac systems or to the /etc/bash_completion.d/ directory on Linux systems. This is a directory of scripts that Bash will automatically load to provide shell completions.

If you’re using Windows with Git Bash, which is the default when installing Git on Windows with msysGit, auto-completion should be preconfigured.

Press the Tab key when you’re writing a Git command, and it should return a set of suggestions for you to pick from:

$ git co<tab><tab>
commit config

In this case, typing git co and then pressing the Tab key twice suggests commit and config. Adding m<tab> completes git commit automatically.

This also works with options, which is probably more useful. For instance, if you’re running a git log command and can’t remember one of the options, you can start typing it and press Tab to see what matches:

$ git log --s<tab><tab>
--shortstat               --sparse
--simplify-by-decoration  --src-prefix=
--simplify-merges         --stat
--since=                  --summary

That’s a pretty nice trick and may save you some time and documentation reading.

Edit - History - Print - Recent Changes - Search
Page last modified on February 22, 2018, at 05:36 PM