Skip to content

Instantly share code, notes, and snippets.

@MattSeen

MattSeen/.gitconfig

Last active Apr 3, 2020
Embed
What would you like to do?
These are a series of the Git alias I use on use on a daily basis. I have included references to the places where I have found each one to give the authors due credit.
[alias]
# Source: http://stackoverflow.com/questions/7066325/how-to-list-show-git-aliases#answer-7067489
# Found on stackoverflow list all available aliases ==
alias = config --get-regexp '^alias.*'
s = status
ss = status --short
ssb = status --short --branch
co = commit
com = commit --message
coma = commit --all --message
# Source: http://stackoverflow.com/questions/2845731/how-to-uncommit-my-last-commit-in-git
# Going to keep it a soft commit for the moment.
uncommit = reset --soft HEAD^
a = add
aa = add --all
rb = rebase
rba = rebase --abort
rbc = rebase --continue
rbs = rebase --skip
# Source: https://ochronus.com/git-tips-from-the-trenches
ds = diff --staged
pr = pull --rebase
branches = branch --all
branchrename = branch --move
branchesdiffed = !git branch | grep -i "indiff"
branchesundiffed = !git branch | grep -v -i "indiff"
# Source: http://stackoverflow.com/a/4755244/1367612
# Since description is used by other git features want a different
# area for my own meta data
branchnote = !git config branch.`git rev-parse --abbrev-ref HEAD`.note
# Source: https://coderwall.com/p/euwpig?i=3&p=1&t=git
# A better git log (subjective obviously) ==
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
# I do this often, need to see the last x number of commits ==
logn = log --max-count
# Source: http://stackoverflow.com/questions/1486819/which-git-commit-stats-are-easy-to-pull
# Show running total of number of commits per dev ==
winning = shortlog --summary --numbered --email
# Source: http://oli.jp/2012/git-powerup/
# The repositories running total of commits ==
total-commits = git log --all --pretty=oneline | wc -l
# Came from Conor Carr of Pilz Ireland ==
incoming = !git remote update --prune; git log ..@{upstream}
outgoing = log @{upstream}..
# Source: http://stackoverflow.com/a/3338774/1367612
unpushed = log --branches --not --remotes --decorate=full --oneline
# Wipe out all local changes you have made, be careful! ==
wipelc = checkout .
# Source: http://stackoverflow.com/a/8858853
# Source: http://stackoverflow.com/a/12142066
# Print the associated description of a branch. ==
# Set descriptions with git branch --edit-description ==
descriptionview = !git config branch.`git rev-parse --abbrev-ref HEAD`.description
descriptionedit = branch --edit-description
# Source: http://www.element84.com/using-git-log-to-show-last-months-commits.html
commitslastmonth = !git log --author=\"`git config user.name`\" --before={`date "+%Y-%m-01"`} --after={`date --date=\"$(date +%Y-%m-1) -1 month\" \"+%Y-%m-01\"`} --reverse --pretty=format:\"%cd %h %s\" --date=short
commitsthismonth = !git log --author=\"`git config user.name`\" --before=now --after={`date "+%Y-%m-1"`} --reverse --pretty=format:\"%cd %h %s\" --date=short
# Source: http://stackoverflow.com/a/5178739/1367612
commitstoday = log --author=\"`git config user.name`\" --since=\"6am\"
# Source: http://www.commandlinefu.com/commands/view/12842/get-a-list-of-all-todofixme-tasks-left-to-be-done-in-your-git-project
todosfind = grep --extended-regexp -I --line-number --break --heading --color=auto "TODO|FIXME"
todoscount = grep --extended-regexp -I --line-number --count "TODO|FIXME"
todosnamefiles = grep --extended-regexp -I --name-only "TODO|FIXME"
[core]
# Use sublime as your default git editor
# Source: http://stackoverflow.com/questions/8951275/git-config-core-editor-how-to-make-sublime-text-the-default-editor-for-git-on#answer-9408117
editor = 'C:/Program Files/Sublime Text 2/sublime_text.exe' --wait --new-window
[web]
browser = c:/Program Files/Mozilla Firefox/firefox.exe
# Source: http://blog.json.codes/developer-tools/using-winmerge-with-git-in-windows/
[diff]
tool = WinMergeU
[difftool "WinMergeU"]
cmd = WinMergeU.exe -e -ub -x -wl -u -maximise -dl "base" -dr "mine" \"$LOCAL\" \"$REMOTE\"
[difftool]
prompt = false
#!/bin/bash
# Straight forward script that lists all your git branch with the age prepended at the start.
# Source: http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches
for k in `git branch|sed s/^..//`;do
echo -e `git log -1 --pretty=format:"%Cgreen%cr%Creset" "$k"`\\t"$k";
done |sort
#!/bin/bash
# bash command to list all git branch descriptions for you current repository
#
# INSTALL
#
# Only recently discovered that git scans your scripts directory when
# searching for commands to run. You can just download this file and place
# it in your /usr/local/bin/ folder or if you are on windows, place them in a
# folder on you path. I've created a folder called git-scripts in my home folder
# and placed my scripts there. The script files need to conform to a file name
# pattern of git-<command name>. Mine is called git-description-view-all
#
# USAGE
#
# execute "git description-view-all" to see a list of all the branch descriptions.
branch_descriptions () {
get_branch_names | sanitize_names | pretty_print_branch_descriptions
}
get_branch_names () {
echo "$(git branch | grep '\w')"
}
# Remove the special character for the branch you are currently in and trim
# any whitespace on the branch names.
# Needs to be a clean set of strings to work with pretty print function
sanitize_names () {
echo "$(sed -e 's/\*//' -e 's/[ ]*//' $1)"
}
pretty_print_branch_descriptions () {
local UNDERLINE="\e[4m"
local BOLD="\e[1m"
local RESET="\e[0m"
local RED="\e[31m"
local GREEN="\e[32m"
while IFS= read -r BRANCH_NAME; do
local branchDescription="$(git config branch."$BRANCH_NAME".description)";
if [[ -n "$branchDescription" ]]
then
echo -e "Branch: $BOLD$RED$BRANCH_NAME$RESET";
echo -e "Description:"
echo -e "$GREEN$branchDescription$RESET"
echo ""
fi
done
}
branch_descriptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.