DEV Community

loading...

The Git Aliases That Get Me To Friday

megamattmiller profile image Matt Miller ・2 min read

The Git Aliases That Get Me To Friday

alt text

In the last few years since switching from SVN to Git, I’ve picked up a few aliases that have helped me streamline my workflow and be all around more productive. After all, the whole point of shortcuts is to make your life easier right? I’d like to share my aliases with you, however unhelpful they may be.

Branching

co = checkout # Shortcut for checkout.
nb = checkout -b # Create a new branch and check it out.
bl = branch -l # List all local branches.
br = branch -r # List all remote branches.
blr = branch -a # Show local and remote branches.
bd = branch -d # Politely ask Git to delete a local branch.
bdf = branch -D # Sternly ask Git to delete a local branch.
Enter fullscreen mode Exit fullscreen mode

Fetching/Syncing/Merging

fp = fetch -p # Fetch and prune.
sync = !git pull && git push # Pull then push current branch.
mm = !git fetch -p && git merge origin/master #Merge remote master into the current branch.
Enter fullscreen mode Exit fullscreen mode

Commits

cm = commit # Shortcut for commit.
cma = commit -a # Commit all tracked.
cmam = commit -a -m # Commit all tracked with message to follow.
runAway = reset --hard # For when you just want it all to go away.
forgetAbout = rm --cached # Make Git forget about a tracked file.
Enter fullscreen mode Exit fullscreen mode

Utilities

alias = config --get-regexp ^alias\\. # List all aliases.
ec = config --global -e # Open .gitconfig in your default editor.
Enter fullscreen mode Exit fullscreen mode

I have all of these and maybe more by time you're reading this in a handy GitHub repo if you'd like to [include] it in your Git config.

I hope these aliases are as useful for you as they are for me.

If you have your own favorite aliases, leave them in the comments below.

Discussion (4)

pic
Editor guide
Collapse
bszeliga profile image
bszeliga

Nice. Here are a handful of my favorites (where we don't overlap):

# What was the last commit
last=log --name-status -1 HEAD

# History of a file
history=!git log --follow --pretty=format:"$(git config --get custom.formats.ls)" --

#Nicer logs
ls=!git log --pretty=format:"$(git config --get custom.formats.ls)" --decorate
ll=!git log --pretty=format:"$(git config --get custom.formats.ls)" --decorate --name-status
graph=!git log --graph --abbrev-commit --decorate --pretty=format:"$(git config --get custom.formats.graph)"

# My version of the alias command
la=!git config -l | grep alias | cut -c 7-

# Where am I?
where=rev-parse --abbrev-ref HEAD

# Pop off that last commit
undo=reset HEAD~1 --mixed

st=status --short

# What do I have locally that's not on the server?
out=!git log --branches="*$(git rev-parse --abbrev-ref HEAD)" --not --remotes=* --pretty=format:"$(git config --get custom.formats.ls)" --decorate

# List my formats
formats=!git config -l | grep "^custom.formats" | cut -c 16-

The formats associated with above:

[custom.formats]
    ls   = "[%C(auto,yellow)%<|(10)%h%C(reset)] [%C(auto,bold blue)%<(15trunc)%cn%C(reset)]  %C(auto)%d% C(reset)%s"
    find = "[%C(yellow)%<|(20)%h%C(reset)] [%C(bold blue)%<(10)%cn%C(reset)]  %C(auto)%d %C(reset)  %s"
    graph="%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)%n %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)"
Collapse
ghost profile image
Ghost

Nice. Here are my personal favorites:

alias.unstage 'reset HEAD --'
alias.append 'commit --amend --no-edit'
alias.last 'log --name-status HEAD^..HEAD'
alias.skip '!git update-index --assume-unchanged'
alias.skipped '!git ls-files -v | grep ^[a-z]'
alias.unskip '!git update-index --no-assume-unchanged'
alias.amend '!git commit --amend'
alias.issues '!f() { URL=$(git config --get remote.origin.url); open ${URL/.git}/issues/$1; }; f'
alias.undo 'reset --soft HEAD^'
alias.discard 'checkout --'
alias.review '!git diff --cached'
alias.release '!git commit -am "Release $1" && git tag -a -m $1'
alias.alias '!git config --get-regexp alias'

gist.github.com/arnaudjuracek/3188...

Collapse
megamattmiller profile image
Matt Miller Author

I'm totally stealing some of these if you don't mind :)

Collapse
mattkocaj profile image