literate-dotfiles/git.org
Thomas Dehaeze bb14d8239c Change indentation of all blocks.
Use (setq org-src-preserve-indentation t) for Emacs.
2021-01-08 01:26:27 +01:00

5.6 KiB

Git Configuration

~/.gitconfig

Aliases

[alias]
  # View abbreviated SHA, description, and history graph of the latest 20 commits
  l = log --pretty=oneline -n 20 --graph --abbrev-commit

  # View the current working tree status using the short format
  s = status -s

  # Show the diff between the latest commit and the current state
  d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"

  di = diff --cached --ignore-all-space

  # Pull in remote changes for the current repository and all its submodules
  p = !"git pull; git submodule foreach git pull origin master"

  # Clone a repository including all submodules
  c = clone --recursive

  # Commit all changes
  ca = !git add -A && git commit -av

  # Switch to a branch, creating it if necessary
  go = "!f() { git checkout -b \"$1\" 2> /dev/null || git checkout \"$1\"; }; f"

  # Show verbose output about tags, branches or remotes
  tags = tag -l
  branches = branch -a
  remotes = remote -v

  # Amend the currently staged files to the latest commit
  amend = commit --amend --reuse-message=HEAD

  # Credit an author on the latest commit
  credit = "!f() { git commit --amend --author \"$1 <$2>\" -C HEAD; }; f"

  # Interactive rebase with the given number of latest commits
  reb = "!r() { git rebase -i HEAD~$1; }; r"

  # Remove the old tag with this name and tag the latest commit with it.
  retag = "!r() { git tag -d $1 && git push origin :refs/tags/$1 && git tag $1; }; r"

  # Find branches containing commit
  fb = "!f() { git branch -a --contains $1; }; f"

  # Find tags containing commit
  ft = "!f() { git describe --always --contains $1; }; f"

  # Find commits by source code
  fc = "!f() { git log --pretty=format:'%C(yellow)%h  %Cblue%ad  %Creset%s%Cgreen  [%cn] %Cred%d' --decorate --date=short -S$1; }; f"

  # Find commits by commit message
  fm = "!f() { git log --pretty=format:'%C(yellow)%h  %Cblue%ad  %Creset%s%Cgreen  [%cn] %Cred%d' --decorate --date=short --grep=$1; }; f"

  # Remove branches that have already been merged with master
  dm = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"

  # List contributors with number of commits
  contributors = shortlog --summary --numbered

  ec = config --global -e

  # Pretty log output
  hist = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all

  pp = pull origin $(git_current_branch)
  gg = push origin $(git_current_branch)
  rhh = reset HEAD --hard

  unstage = reset HEAD --
  last = log -1 HEAD

Apply

[apply]
  # Detect whitespace errors when applying a patch
  whitespace = fix

Colors

[color]
  # Use colors in Git commands that are capable of colored output when outputting to the terminal
  ui = true

[color "branch"]
  current = yellow reverse
  local = yellow
  remote = green
  HEAD = red bold

[color "diff"]
  meta = yellow bold
  frag = magenta bold # line info
  old = red # deletions
  new = green # additions

[color "status"]
  added = green
  changed = yellow
  untracked = cyan

[color "decorate"]
  HEAD = red bold
  branch = green
  remoteBranch = cyan
  tag = yellow
  stash = bold yellow

Default Remote

# Use `origin` as the default remote on the `master` branch in all cases
[branch "master"]
  remote = origin
  merge = refs/heads/master

Push Configuration

[push]
  default = matching
  # Make `git push` push relevant annotated tags when pushing branches out.
  followTags = true

User

[user]
  name = Thomas Dehaeze
  email = dehaeze.thomas@gmail.com

Core configuration

[core]
  # Use custom `.gitignore` and `.gitattributes`
  excludesfile = ~/.gitignore_global

  # Treat spaces before tabs and all kinds of trailing whitespace as an error
  # [default] trailing-space: looks for spaces at the end of a line
  # [default] space-before-tab: looks for spaces before tabs at the beginning of a line
  whitespace = space-before-tab,-indent-with-non-tab,trailing-space

  # Prevent showing files whose names contain non-ASCII symbols as unversioned.
  # http://michael-kuehnel.de/git/2014/11/21/git-mac-osx-and-german-umlaute.html
  precomposeunicode = false

  pager = diff-so-fancy | less --tabs=4 -RFX

  autocrlf = input

  # Open vim, start Goyo and enter insert mode on the first line
  editor = "nvim -c ':Goyo' -c 'goto 1' -c 'startinsert'"

Credentials using pass

[credential]
    helper = !pass-git-helper $@

[credential "https://github.com"]
    username = tdehaeze

[credential "https://git.tdehaeze.xyz"]
    username = tdehaeze

[credential "https://gitlab.esrf.fr"]
    username = dehaeze

Diff-so-fancy

[diff-so-fancy]
  markEmptyLines = false

Github

[github]
  user = tdehaeze
  oauth-token = 8cc5b41120f7e9a869c24fa3678667d3d8422e6f

~/.gitignore_global - Global Git Ignore

*~
.DS_Store
Session.vim

pass-git-helper - Use pass for git passwords

[github.com*]
target=github.com/tdehaeze

[git.tdehaeze.xyz*]
target=git.tdehaeze.xyz/tdehaeze

[gitlab.esrf.fr*]
target=gitlab.esrf.fr/dehaeze