Please keep this config simple. It should be a starting point for new developers learning Git.
[user]
name = Your Name
email = your.name@domain.com
[branch]
sort = -committerdate
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
whitespace = white reverse
meta = blue reverse
frag = blue reverse
old = red
new = green
[color "status"]
added = green
changed = yellow
untracked = cyan
[interactive]
singlekey = true # Do not require [enter] in interactive rebase
[pull]
default = current # Match remote branch with same name
[push]
autosetupremote = true # Start tracking the remote branch; enables pulling
default = current # Match remote branch with same name
For more configuration examples, read on. Please only use configuration that you understand.
[alias]
amend = commit -v --amend # Amend changes to last commit
b = branch -v --sort=committerdate # Sort branches by latest update ASC + show latest commit message
c = commit -v -m # Commit from command line. Usage: git c "commit message"
du = diff @{upstream} # Diff against upstream
lc = show --name-status # Show last commit
lou = log --oneline @{upstream}.. # List unpushed commits
uncommit = reset HEAD~ --soft
riom = rebase -i origin/master # Handy with prior `git fetch` to rebase a feature branch onto its remote target
riu = rebase -i @{upstream}
"Upstream" is the remote branch where your current local branch is pulling from and pushing to.
These might require extra configuration in Gitlab.
[alias]
# Push branch, create a merge request and set the branch to be removed on merge
pmr = push -u origin HEAD -o merge_request.create -o merge_request.remove_source_branch
# If you do not need a code review, but use the merge request to run a test pipeline:
# Push branch, create a merge request, set the branch to be removed on merge and set to merge when all tests are green
ptm = push -u origin HEAD -o merge_request.create -o merge_request.merge_when_pipeline_succeeds -o merge_request.remove_source_branch
[core]
editor = vim # Set the editor for commit messages, interactive rebases etc.
excludesfile = ~/.gitignore # Global .gitignore, see https://makandracards.com/makandra/15947
[diff]
algorithm = patience # A slower algorithm that sometimes produces better diffs
[fetch]
prune = true # Remove local remote-tracking branches that have been deleted
[rebase]
autoStash = true # Stash your local changes while rebasing, and re-apply afterwards
If you prefer to rebase instead of merge:
[branch]
autosetuprebase = always
[pull]
rebase = true
tig is a powerful Git interface. Highly recommended.
[tig]
main-view = date:relative author:abbreviated commit-title:graph=true,refs:true
You may switch to delta Show archive.org snapshot , a fancy diff tool with syntax highlighting and inline change highlighting.
git-delta_*_amd64.deb
file
from the releases page
Show archive.org snapshot
. On Ubuntu 20.04, I had to use v14.0 because of dependenciesdpkg -i path/to/git-delta*.deb
[core]
pager = delta
[interactive]
difffilter = delta --color-only
See Rails developers: Have better context in Git diffs. This will correctly identify the beginning of a method instead of showing the complete class within the diff.
The value for color configuration variables is a list of 1-2 colors and 0-1 attributes, separated by spaces.