Last active
April 2, 2018 01:36
-
-
Save localpcguy/2fb762c579a39747734f7d0673002fff to your computer and use it in GitHub Desktop.
Bunch of aliases for git commands, some my own, others pulled from various blog posts, stack overflow comments and other places online
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
[alias] | |
co = checkout | |
ci = commit | |
st = status | |
br = branch | |
fl = log -u | |
filelog = log -u | |
del = branch -d | |
delr = push origin -d | |
df = diff | |
ds = diff --stat | |
dc = diff --cached | |
m = merge --no-ff | |
lg = log -p | |
slog = log --pretty=oneline --abbrev-commit | |
plog = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short | |
hist = log --graph --abbrev-commit --decorate --date=short --pretty=format:\"%C(bold cyan)%h%C(reset) - %Creset%C(bold yellow)%ad%C(reset) |%C(yellow)%d%C(reset) %C(white)%s %C(cyan)- %an, %C(reset)%ar%C(reset)\" | |
histall = log --graph --abbrev-commit --decorate --date=short --pretty=format:\"%C(bold cyan)%h%C(reset) - %Creset%C(bold yellow)%ad%C(reset) |%C(yellow)%d%C(reset) %C(white)%s %C(cyan)- %an, %C(reset)%ar%C(reset)\" --all | |
array = log --no-color --pretty=format:'[ "%h", "%s", "%cr", "%an" ],' --abbrev-commit | |
type = cat-file -t | |
dump = cat-file -p | |
sl = stash list | |
sa = stash apply | |
ss = stash save | |
unstage = reset HEAD -- | |
ap = !git add . -p && git status | |
cb = rev-parse --abbrev-ref HEAD | |
current = rev-parse --abbrev-ref HEAD | |
pb = !"git show-branch -a | ack '\\*' | ack -v \"`git cb`\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'" | |
parent = !"git show-branch -a | ack '\\*' | ack -v \"`git cb`\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'" | |
version = describe --abbrev=0 | |
ver = describe --abbrev=0 | |
v = describe --abbrev=0 | |
praise = blame | |
last = log -1 HEAD | |
list = --global | |
mt = mergetool | |
lb = checkout - | |
# The following are from https://gist.github.com/robmiller/6018582 and comments | |
# | |
# Working with branches | |
# | |
# Get the current branch name (not so useful in itself, but used in other aliases) | |
branch-name = "!git rev-parse --abbrev-ref HEAD" | |
# Push the current branch to the remote "origin", and set it to track the upstream branch | |
publish = "!git push -u origin $(git branch-name)" | |
pub = "!git push -u origin $(git branch-name)" | |
# Delete the remote version of the current branch | |
unpublish = "!git push origin :$(git branch-name)" | |
unpub = "!git push origin :$(git branch-name)" | |
# Delete a branch and recreate it from master — useful if you have, say, | |
# a development branch and a master branch and they could conceivably go out of sync | |
recreate = "!f() { [[ -n $@ ]] && git checkout \"$@\" && git unpublish && git checkout master && git branch -D \"$@\" && git checkout -b \"$@\" && git publish; }; f" | |
# Fire up your difftool (e.g. Kaleidescope) with all the changes that are on the current branch. | |
code-review = difftool origin/master... | |
# Given a merge commit, find the span of commits that exist(ed) on that | |
# branch. Again, not so useful in itself, but used by other aliases. | |
merge-span = "!f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f" | |
# Find the commits that were introduced by a merge | |
merge-log = "!git log `git merge-span .. $1`" | |
# Show the changes that were introduced by a merge | |
merge-diff = "!git diff `git merge-span ... $1`" | |
# As above, but in your difftool | |
merge-difftool = "!git difftool `git merge-span ... $1`" | |
# Check merge for conflicts without commiting | |
mergetest = "!f(){ git merge --no-commit --no-ff \"$1\"; git merge --abort; echo \"Merge aborted\"; };f " | |
mt = "!f(){ git merge --no-commit --no-ff \"$1\"; git merge --abort; echo \"Merge aborted\"; };f " | |
# Interactively rebase all the commits on the current branch | |
rebase-branch = "!git rebase -i `git merge-base master HEAD`" | |
# Branch commit - like "git commit -m" but prefixes commit message with branch name in square brackets | |
branch-commit = "!f() { bname=\"[$(git symbolic-ref --short HEAD)] \"; read -i \"$bname\" -e && [[ ${#bname} -lt ${#REPLY} ]] && git commit -m \"$REPLY\" || echo aborted; }; f; unset f bname" | |
bc = "!f() { bname=\"[$(git symbolic-ref --short HEAD)] \"; read -i \"$bname\" -e && [[ ${#bname} -lt ${#REPLY} ]] && git commit -m \"$REPLY\" || echo aborted; }; f; unset f bname" | |
# | |
# Working with files | |
# | |
# Unstage any files that have been added to the staging area | |
unstage = reset HEAD | |
# Show changes that have been staged | |
diffc = diff --cached | |
# Mark a file as "assume unchanged", which means that Git will treat it | |
# as though there are no changes to it even if there are. Useful for | |
# temporary changes to tracked files | |
assume = update-index --assume-unchanged | |
# Reverse the above | |
unassume = update-index --no-assume-unchanged | |
# Show the files that are currently assume-unchanged | |
assumed = "!git ls-files -v | grep ^h | cut -c 3-" | |
# Checkout our version of a file and add it | |
ours = "!f() { git checkout --ours $@ && git add $@; }; f" | |
# Checkout their version of a file and add it | |
theirs = "!f() { git checkout --theirs $@ && git add $@; }; f" | |
# Delete any branches that have been merged into master | |
# See also: https://gist.github.com/robmiller/5133264 | |
delete-merged-branches = "!git co master && git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d" | |
# Save all work into a commit "FIRE" | |
fire = "!git add -A && git commit -m 'FIRE FIRE FIRE' && git push origin fire-branch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment