Useful Git Aliases05 Jan 2018
I am always looking to make my life easier, quicker and typing less so I rely heavily on Keyboard Shortcuts and so the following Aliases really help me out.
I have actually decided to create this post mostly for my own benefit, but hopefully many of you may benefit from a lot of these aliases that I use day to day with git.
So here they are…
Synopsis: This shows a one line log of commits with a graph, short commit hash, short date, Single Line Commit, and Author. This makes reading the logs at a glance very easy.
git hist OR
git hist -5
hist = log --pretty=format:\"%C(auto)%h %ad | %s%d [%an]\" --graph --date=short #--color
Directory Difference Comparison
Synopsis: This will launch your specified difftool (for me this is BeyondCompare4) with the
--dir-diff option to allow you to do a folder/directory comparison between branches/commits/staged/unstaged changes.
git dirdiff OR
git dirdiff master OR
git dirdiff master..somebranch OR
git dirdiff --cached
dirdiff = difftool -t bc4 --dir-diff
Initial Push and Track Remote Branch
Synopsis: I use this for my initial pushes to the remote repository of a new local branch, which adds the option to Track the remote branch.
pushy = push -u origin
Launch Merge Tool
Synopsis: Shorthand to launch my configured merge tool.
mt = mergetool
Add All Files
Synopsis: Shorthand to Add All files, including untracked files, to the staging area.
aa = add -A
Force Push Changes
Synopsis: Shorthand to force push all changes to the remote repository.
pf = push -f
Synopsis: Shorthand to ReBase from the Master branch.
rbm = rebase master
Interactively Rebase Master
Synopsis: Shorthand to ReBase from the Master branch Interactively using the
rbmi = rebase master -i
Synopsis: Shorthand to continue with a rebase after a merge conflict has been resolved.
rbc = rebase --continue
Synopsis: Shorthand to abort a rebase during merge conflicts.
rba = rebase --abort
Synopsis: Shorthand to skip a merge conflict during a rebase.
rbs = rebase --skip
Checkout a New Local Branch
Synopsis: Shorthand to CheckOut a New local branch.
git con mybranchname
con = checkout -b
Checkout Master Branch
Synopsis: Shorthand to CheckOut the Master branch.
com = checkout master
Commit with Message
Synopsis: Shorthand to Commit with a Message.
git cm "My Short Commit Message"
cm = commit -m
Amend the last commit
Synopsis: Shorthand to ammend the last commit.
ca = commit --amend
Delete Local Branch
Synopsis: Shorthand to Delete local Branch.
git db mybranchtodelete
db = branch -d
Force Delete Local Branch
Synopsis: Shorthand to Delete local Branch with
git dbf mybranchtodelete
dbf = branch -D
Delete Remote Branch
Synopsis: Shorthand to Delete Remote Branch.
git drb mybranchtodelete
drb = push origin --delete
Delete all local branches that are merged
Synopsis: Delete all local branches that have been merged into the main branch.
cleanup = "!git branch --merged | grep -v '\\*\\|master\\|develop' | xargs -n 1 git branch -d"
Reset HEAD and Delete Changes
Synopsis: Shorthand to Reset HEAD Hard as with the
--hard option which will reset your local branch back to the HEAD and remove all changes.
rhh = reset HEAD --hard
Synopsis: Shorthand to List local Branches.
lb = branch -vl
List Branches including remote
Synopsis: Shorthand to List Branches All which includes remote branches.
lba = branch -vla
Force Clean Branch
Synopsis: Shorthand to Clean and Force all Files and Untracked Files/Directories.
cf = clean -fd
Synopsis: Shorthand to Push Tags to the remote repository.
pt = push --tags
Fetch All Changes
Synopsis: Shorthand to Fetch All changes from the remote repository.
fa = fetch --all
Edit the Global Git Config
Synopsis: Shorthand to Edit your Global git Config file.
egc = config --global -e