Last active
August 4, 2020 07:45
-
-
Save NigelThorne/dcb2ff06c6b48eccd9c547260937b4b4 to your computer and use it in GitHub Desktop.
Git Aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | |
# `git di $number` shows the diff between the state `$number` revisions ago and the current state | |
di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d" | |
# 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 | |
# a.k.a. ‘delete merged’ | |
dm = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d" | |
# List contributors with number of commits | |
contributors = shortlog --summary --numbered | |
# Merge GitHub pull request on top of the `master` branch | |
mpr = "!f() { \ | |
if [ $(printf \"%s\" \"$1\" | grep '^[0-9]\\+$' > /dev/null; printf $?) -eq 0 ]; then \ | |
git fetch origin refs/pull/$1/head:pr/$1 && \ | |
git rebase master pr/$1 && \ | |
git checkout master && \ | |
git merge pr/$1 && \ | |
git branch -D pr/$1 && \ | |
git commit --amend -m \"$(git log -1 --pretty=%B)\n\nCloses #$1.\"; \ | |
fi \ | |
}; f" | |
my-changes = !git dt $(git merge-base HEAD origin/master) | |
alias = !git config --list | grep 'alias\\.' | sed 's/^alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\t=> \\2/' | sort | |
create-pull-request = !sh -c 'stash pull-request \\$0' | |
difftool = difftool -y | |
dl = log --oneline master..HEAD | |
dt = difftool --dir-diff | |
gg = log --oneline --abbrev-commit --all --graph --decorate --color | |
graph = log --graph -20 --branches --remotes --tags --format=format:'%Cgreen%h %Creset• %<(75,trunc)%s (%cN, %cr) %Cred%d' --date-order | |
ignore=!([ ! -e .gitignore ] && touch .gitignore) | echo >> .gitignore | |
m = mergetool -y | |
precommit = diff --cached --diff-algorithm=minimal -w | |
pull = pull --recurse-submodules | |
pushu = !git push --set-upstream origin `git symbolic-ref --short HEAD` | |
r = !git ls-files -z --deleted | xargs -0 git rm | |
review-me = !sh -c 'cmd.exe /c \"@e:\\bin\\send_for_review.bat $0\" ' | |
serve = daemon --verbose --export-all --base-path=.git --reuseaddr --strict-paths .git/ | |
st = status | |
this = !git init && git add . && git commit -m \"initial commit\" | |
undo = reset HEAD~1 --mixed | |
unstage = !sh -c \"echo -e \\\"NigTip: Use 'git wipe' to unstange all files\\n Use 'git reset -- file' for one file\\\"\" | |
amend = !git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend | |
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs git branch -d; }; f" | |
bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1-master}; }; f" | |
branch-list = for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) (%(color:green)%(committerdate:relative)%(color:reset)) %(color:yellow)%(refname:short)%(color:reset) ------ %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) ' | |
branch-list-local = for-each-ref --sort=-committerdate --no-merged origin/master refs/heads/ --format='%(HEAD) (%(color:green)%(committerdate:relative)%(color:reset)) %(color:yellow)%(refname:short)%(color:reset) ------ %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) ' | |
unpushed-branches = !git log --branches --not --remotes --no-walk --decorate --oneline | |
bl = branch-list | |
bll = branch-list-local | |
cm = !git add -A && git commit -m | |
co = checkout | |
cob = checkout -b | |
ec = config --global -e | |
save = !git add -A && git commit -m 'SAVEPOINT' | |
# sup = !git branch --set-upstream-to=origin/`git symbolic-ref --short HEAD` | |
update-master = !sh -c 'git checkout -q --detach && git fetch origin master:master && git checkout -q -' | |
mup = !git update-master | |
up = !git pull --rebase --prune $@ && git submodule update --init --recursive | |
wip = !git add -u && git commit -m "WIP" | |
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can "git config include.path '../.gitalias' " to allow projects to have their own .gitalias per project.
as per https://www.pix-art.be/post/how-to-create-custom-git-aliases-for-a-project