Useful Git Aliases

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ā€¦

Aliases

History


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.

Usage: git hist OR git hist -5

Config

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.

Usage: git dirdiff OR git dirdiff master OR git dirdiff master..somebranch OR git dirdiff --cached

Config

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.

Usage: git pushy

Config:

pushy = push -u origin

Launch Merge Tool


Synopsis: Shorthand to launch my configured merge tool.

Usage: git mt

Config:

mt = mergetool

Add All Files


Synopsis: Shorthand to Add All files, including untracked files, to the staging area.

Usage: git aa

Config:

aa = add -A

Force Push Changes


Synopsis: Shorthand to force push all changes to the remote repository.

Usage: git pf

Config:

pf = push -f

Rebase Master


Synopsis: Shorthand to ReBase from the Master branch.

Usage: git rbm

Config:

rbm = rebase master

Interactively Rebase Master


Synopsis: Shorthand to ReBase from the Master branch Interactively using the -i option.

Usage: git rbm

Config:

rbmi = rebase master -i

Continue Rebase


Synopsis: Shorthand to continue with a rebase after a merge conflict has been resolved.

Usage: git rbc

Config:

rbc = rebase --continue

Abort Rebase


Synopsis: Shorthand to abort a rebase during merge conflicts.

Usage: git rba

Config:

rba = rebase --abort

Skip Rebase


Synopsis: Shorthand to skip a merge conflict during a rebase.

Usage: git rbs

Config:

rbs = rebase --skip

Checkout a New Local Branch


Synopsis: Shorthand to CheckOut a New local branch.

Usage: git con mybranchname

Config:

con = checkout -b

Checkout Master Branch


Synopsis: Shorthand to CheckOut the Master branch.

Usage: git com

Config:

com = checkout master

Commit with Message


Synopsis: Shorthand to Commit with a Message.

Usage: git cm "My Short Commit Message"

Config:

cm = commit -m

Amend the last commit


Synopsis: Shorthand to ammend the last commit.

Usage: git ca

Config:

ca = commit --amend

Delete Local Branch


Synopsis: Shorthand to Delete local Branch.

Usage: git db mybranchtodelete

Config:

db = branch -d

Force Delete Local Branch


Synopsis: Shorthand to Delete local Branch with Force.

Usage: git dbf mybranchtodelete

Config:

dbf = branch -D

Delete Remote Branch


Synopsis: Shorthand to Delete Remote Branch.

Usage: git drb mybranchtodelete

Config:

drb = push origin --delete

Delete all local branches that are merged


Synopsis: Delete all local branches that have been merged into the main branch.

Config

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.

Usage: git rhh

Config:

rhh = reset HEAD --hard

List Branches


Synopsis: Shorthand to List local Branches.

Usage: git lb

Config:

lb = branch -vl

List Branches including remote


Synopsis: Shorthand to List Branches All which includes remote branches.

Usage: git lba

Config:

lba = branch -vla

Force Clean Branch


Synopsis: Shorthand to Clean and Force all Files and Untracked Files/Directories.

Usage: git cf

Config:

cf = clean -fd

Push Tags


Synopsis: Shorthand to Push Tags to the remote repository.

Usage: git pt

Config:

pt = push --tags

Fetch All Changes


Synopsis: Shorthand to Fetch All changes from the remote repository.

Usage: git fa

Config:

fa = fetch --all

Edit the Global Git Config


Synopsis: Shorthand to Edit your Global git Config file.

Usage: git egc

Config:

egc = config --global -e