Skip to content

Instantly share code, notes, and snippets.

@maninak
Last active February 20, 2024 10:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maninak/ef1c6d1ec312fa0e3a716688fbc62e59 to your computer and use it in GitHub Desktop.
Save maninak/ef1c6d1ec312fa0e3a716688fbc62e59 to your computer and use it in GitHub Desktop.
My git-config & aliases. Place this file in your home folder (e.g.: /home/maninak/.gitconfig). Learn more: https://medium.com/@maninak/git-fancy-with-your-version-control-a3a895d1dede
[user]
email = your@email.com
name = Firstname Lastname
[merge]
# delete if you don't use meld
tool = meld # sudo apt-get install meld
conflictStyle = diff3
[init]
defaultBranch = master
[branch]
autosetuprebase = always
[push]
default = simple
followTags = true
gpgSign = if-asked
[rerere]
enabled = true
[alias]
# initializes your repo and creates an empty root commit in one quick step
it = !git init && git commit -m “root” --allow-empty
# git status in short
s = status --short --branch
# stages all changed tracked and untracked files
a = git add -A
# git commit
c = commit
# git commit -m
cm = commit -m
# git checkout
ch = checkout
# add tracked and untracked changes and commit
ac = !git add -A && git commit
# as ac but can be used like `git acm "did some changes"`
acm = !git add -A && git commit -m $2
# includes any staged files into the last commit you created; typo-compliant
camend = commit --amend --no-edit --reset-author
cammend = commit --amend --no-edit --reset-author
# same as camend, but allows you to edit commit message too; typo-compliant
camendm = commit --amend --reset-author
cammendm = commit --amend --reset-author
# same as camend, but also adds all unstaged changes before commit; typo-compliant
acamend = !git add -A && git commit --amend --no-edit --reset-author
acammend = !git add -A && git commit --amend --no-edit --reset-author
# same as camend, but also adds all unstaged changes before commit
# also allows you to edit commit message too; typo-compliant
acamendm = !git add -A && git commit --amend --reset-author
acammendm = !git add -A && git commit --amend --reset-author
# remove latest commit in checked out branch and dump all changes in working tree
undo = reset --soft HEAD^
# mimic working tree with that of latest commit in checked out branch (dump uncommited changes)
reshard = !git reset --hard && git clean -df
# remove all ignored and non-ignored untracked files and folders (applies for submodules too)
purge = clean -ffdx :/
# update local branches which track remote branches
p = pull --all
# delete all local branches that are already merged into main branch
prune = !git branch --merged $([[ $1 != \"-f\" ]] \\\n&& git rev-parse develop) | egrep -v \"(^\\*|^\\s*(master|main|production|prod|dev|develop|sandbox)$)\" \\\n| xargs git branch -d
# before push and overwrite, checks your local copy is up-to-date with origin (<3)
please = push --force-with-lease
# git stsh # stash only unstaged changes to tracked files
# git stash # stash any changes to tracked files (vanilla git command)
# git staash # stash untracked and tracked files
# git staaash # stash ignored, untracked, and tracked files
stsh = stash save --keep-index
staash = stash save --include-untracked
staaash = stash save --all
# compact log
l = log --pretty=format:'%Cred%h%Creset %s %Cgreen(%cr) %C(blue)%an%Creset%C(yellow)%d%Creset' --abbrev-commit --date=relative
# graphical log
gl = log --color --graph --all --pretty=format:\"%Cred%h%Creset %s %Cgreen(%cr) %C(blue)%an%Creset%C(yellow)%d%Creset\" --abbrev-commit
# Churn means "frequency of change". You'll get an output like this:
#
# $ git churn
# 1 file1
# 22 file2
# 333 file3
#
# This means that file1 changed one time, file2 changes 22 times, and file3
# changes 333 times.
#
# Show churn for whole repo:
# $ git churn
#
# Show churn for specific directories:
# $ git churn app lib
#
# Show churn for a time range:
# $ git churn --since='1 month ago'
churn = !sh -c 'git log --all -M -C --name-only --format='format:' "$@" | sort | grep -v '^$' | uniq -c | sort -n'
# Check out a particular gitlab merge request from any repository and any remote
# For example, to check out the merge request with ID 5 as shown in GitLab from the origin remote, do:
# $ git mr origin 5
mr = !sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' -
# show repository contribution stats (requires git-fame https://github.com/casperdcl/git-fame/)
brag = fame --branch=master --whitespace --exclude="./**/assets/*,package-lock.json,yarn-lock"
# show git aliases
aliases = config --get-regexp alias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment