Last active
June 1, 2018 14:54
-
-
Save igbanam/c1044a0637bc1e599bb1bdfe6a8f57af to your computer and use it in GitHub Desktop.
My Git Aliases
This file contains 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] | |
a = add | |
b = branch | |
c = commit | |
d = diff | |
l = log | |
o = checkout | |
p = pull | |
r = remote | |
s = status | |
### branch ### | |
# branch - soft delete | |
bd = branch --delete | |
# branch - hard delete | |
bdd = branch --delete --force | |
branches-age = !"for branch in `git branch -r | grep -v HEAD`;do echo `git show --format='%ci %cr' $branch | head -n 1` \t$branch; done | sort -r" | |
branches-ages = branch -r --sort=-committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' | |
### commit ### | |
# commit - amend the tip of the current branch rather than creating a new commit. | |
ca = commit --amend | |
# commit - amend the tip of the current branch, and do not edit the message. | |
can = commit --amend --no-edit | |
# commit interactive | |
ci = commit --interactive | |
# commit with a message | |
cm = commit --message | |
### diff ### | |
# diff - show changes not yet staged | |
dc = diff --cached | |
# diff - changes about to be commited | |
ds = diff --staged | |
# diff - show changes but by word, not line | |
dw = diff --word-diff | |
### log ### | |
# log with a text-based graphical representation of the commit history. | |
lg = log --graph | |
# log with one line per item. | |
lo = log --oneline | |
# log relative | |
lr = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an%d%Creset %s %Cgreen(%cr)%Creset' --date=relative | |
### pull ### | |
# pull if a merge can be resolved as a fast-forward, otherwise fail. | |
pf = pull --ff-only | |
# pull with rebase - to provide a cleaner, linear, bisectable history. | |
pr = pull --rebase | |
### rebase ### | |
# rebase - forward-port local commits to the updated upstream head. | |
rb = rebase | |
# rebase - continue the rebasing process after resolving a conflict manually and updating the index with the resolution. | |
rbc = rebase --continue | |
# rebase - restart the rebasing process by skipping the current patch. | |
rbs = rebase --skip | |
# See https://blog.filippo.io/git-fixup-amending-an-older-commit/ | |
# This is a slightly modified version | |
fixup = "!f() { TARGET=$(git rev-parse \"$1\"); git commit --fixup=$TARGET && GIT_EDITOR=true git rebase --interactive --autosquash $TARGET~; }; f" | |
### reflog ### | |
# reflog - reference log that manages when tips of branches are updated. | |
rl = reflog | |
# Push to all remotes | |
push-to-all-remotes = !git remote | xargs -I% -n1 git push % | |
### status ### | |
# status with short format instead of full details | |
ss = status --short | |
# status with short format and showing branch and tracking info. | |
ssb = status --short --branch | |
# Diffs | |
diff-all = !"for name in $(git diff --name-only $1); do git difftool $1 $name & done" | |
diff-branch-changes = !"git diff-changes `git fork-point`..HEAD" | |
diff-branch-files-changed = !"git diff-stat `git fork-point`..HEAD | grep files | awk '{print $1}'" | |
diff-changes = diff --name-status -r | |
diff-stat = diff --stat --ignore-space-change -r | |
diff-staged = diff --cached | |
### LOG ALIASES ### | |
# Show log of changes, most recent first | |
log-changes = log --oneline --reverse | |
# Show log of new commits after you fetched, with stats, excluding merges | |
log-fresh = log ORIG_HEAD.. --stat --no-merges | |
# Show log with dates in our local timezone | |
log-local = log --date=local | |
# Show the log for my own user email | |
log-me = !git log --author $(git config user.email) | |
# Show log as a graph | |
log-graph = log --graph --all --oneline --decorate | |
# Show the date of the first commit | |
log-first-date = !"git log --date-order --date=iso --pretty=%ad --reverse | head -1" | |
# Show the recent day | |
log-day = log --since yesterday | |
# Summarize your own changes since yesterday, suitable for a daily standup meeting. | |
log-standup = !git log --since yesterday --author $(git config user.email) --pretty=short --oneline | |
# Summarize your own changes for the past week. This was created for a | |
# retrospective meeting. If your sprints span more than one week, you can | |
# adjust this to fit the time. | |
log-retro = !git log --since '1 week ago' --author $(git config user.email) --pretty=short --oneline | |
# TODO | |
log-refs = log --all --graph --decorate --oneline --simplify-by-decoration --no-merges | |
log-timeline = log --format='%h %an %ar - %s' | |
log-local = log --oneline origin..HEAD | |
log-fetched = log --oneline HEAD..origin/master | |
# Show who contributed with summarized changes | |
who = shortlog --summary -- | |
# Show who contributed, in descending order by number of commits | |
whorank = shortlog --summary --numbered --no-merges | |
# Show contributors to a file or folder | |
whotouched = !"f() { git log --pretty=\"format:%an%x09\" $@ | sort | uniq; }; f" | |
# Publish the current branch by pushing it to the remote "origin", | |
# and setting the current branch to track the upstream branch. | |
publish = !"git push --set-upstream origin $(git branch-name)" | |
# Unpublish the current branch by deleting the | |
# remote version of the current branch. | |
unpublish = !"git push origin :$(git branch-name)" | |
# "Ancestral Bounds" | |
# These two commands seek to get the internal boundaries of a branch. In the | |
# case of the graph below, the oldest ancestor of topic-branch is G and the | |
# youngest descendant of topic-branch is J. | |
# -- X -- A -- B -- C -- D -- F (master) | |
# \ / \ / | |
# \ / \ / | |
# G -- H -- I -- J (topic-branch) | |
oldest-ancestor = !bash -c 'diff --unified <(git rev-list --first-parent "${1:-HEAD}") <(git rev-list --first-parent "${2:-master}") | grep "^\\-[a-z0-9]" | sed -ne "s/^\\-//p" | tail -n 1' - | |
oldest-ancestor-2 = !"git log ${1:-master}..${2:-HEAD} --oneline | tail -1 | awk '{print $1}'" | |
fork-point = !bash -c 'diff --unified <(git rev-list --first-parent "${1:-HEAD}") <(git rev-list --first-parent "${2:-master}") | grep "^\\ [a-z0-9]" | sed -ne "s/^\\ //p" | head -n 1' - | |
### Rails ### | |
rspec-branch = !"git diff-branch-changes | awk '{print $2}' | grep _spec.rb | xargs rspec" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment