Suggested git configuration options (put in ~/.gitconfig
).
Enables colour and columnised output when output is to a terminal.
[color]
ui = auto
[column]
ui = auto
[pull]
rebase = true
By default, if you want to grab a branch from the remote and work on it the process is tedious. You have to:
git checkout origin/someBranch
: Now you have detached-head at the position of the branchgit branch myLocalBranch
: Make a local branch to refer to this remote one.git branch --set-upstream-to=origin/someBranch myLocalBranch
: Make that new local branch track the remote onegit checkout myLocalBranch
: Check out your local one.
If, like me, you don't care about being able to give the local one a different name from the remote
one, you can configure git such that just executing git checkout someBranch
will automatically do
all of the above, creating a local branch called someBranch
tracking the unique remote branch by that
name. You'll still have to do it the long way in cases where this is ambiguous.
[branch]
autosetuprebase = always
autosetupmerge = true
[core]
autocrlf = false
trustctime = false
Renormalize tells git to ignore whitespace and line-ending changes for the purposes of conflict resolution, and patience has it use a more computationally expensive (but better) diff algorithm which will tend to produce smaller conflict regions when a conflict does occur.
[merge]
renormalize = true
Enable the patience diff algorithm to get smaller diffs in some corner cases.
colorMoved
will highlight moved lines in a different colour from adds/deletions in git diff
output.
This is very nifty.
noprefix
prevents git diff
from prefixing a/
and b/
to every filename in the output, which is
fairly useless in the first place...
renames = copy
enables copy detection as well as rename detection, and renameLimit
prevents git
from giving up on copy/rename detection (you have enough compute power, honest).
[diff]
algorithm = patience
colorMoved = true
noprefix = true
renames = copy
renameLimit = 999999
[status]
submoduleSummary = true
[submodule]
# Fetch submodules in five threads.
fetchJobs = 5
[stash]
showPatch = true
The only difference from the default here is to enable tab-in-indent
, which makes git detect and
highlight indentation using tabs instead of spaces.
[core]
whitespace=blank-at-eol,space-before-tab,tab-in-indent,trailing-space
If you typo a git command, but it is within a small edit distance of only one other command, this will cause git to simply run that command instead.
[help]
autocorrect = -1
Setting a positive number instead will cause git to tell you what it's going to do, and only run the command after that many deciseconds.
Use all cores when packing.
[pack]
threads = 0
See the manual.
Git allows you to specify a "template directory" which is copied into .git
whenever a repo is cloned
or initialised.
[init]
# Set a git template directory.
templatedir = /home/whatever/.git-templates
A suggested templatedir contents is provided here. If you use this one verbatim, you'll also want to add the following hook configuration block.
[hooks]
stopbinaries = true
stopsecrets = true
To retroactively apply a templatedir to existing repos, just run git init
in them after configuring
it.
.git/info/exclude
allows you to configure local-only gitignore rules. This allows you to set up local
ignores for files created by your editors/IDEs/tools without having to fill the repo's own .gitignore
with stuff specific to your environment. It's a good idea to set this file in your templatedir to cover
tools you like to use, so you can forget the issue forever.
The example templatedir in this repo includes hooks that:
- Stop you committing private keys. (toggle with
hooks.stopsecrets
setting) - Stop your committing large binaries without using
git lfs
. (toggle withhooks.stopbinaries
setting) - Stop you from pushing when duplicated submodules are locally checked out to different states. This indicates you might not have tested what you think you did, so may be about to push a mistake.
- Prevents you from doing merges/rewrites when you have un-initialised submodules.