DEV Community

Dale Zak
Dale Zak

Posted on • Originally published at dalezak.Medium

Git Aliases Are Like Superpowers

Using Git Aliases can make you feel like you have superpowers!

It wasn’t until recently that I discovered Git Aliases, they are so handy that I seriously don’t know how I lived without them. These are two that I use every day now.

Git Add Commit Push

git config — global alias.add-commit-push '!git add -A && git commit -m "$1" && git push && git status'
Enter fullscreen mode Exit fullscreen mode

Once the alias has been added you can now add, commit and push all on one line.

git add-commit-push "Add, commit, push in one line!"
Enter fullscreen mode Exit fullscreen mode

Git New Branch

git config --global alias.new-branch '!git checkout -b "$1" && git add -A && git commit -m "$2" && git push -u origin "$1" && git status'
Enter fullscreen mode Exit fullscreen mode

This alias adds, commits and pushes current changes to a new branch.

git new-branch "123-my-branch" "Checkout, add, commit, push!"
Enter fullscreen mode Exit fullscreen mode

Checkout the Git documentation for other alias ideas. Enjoy!

Top comments (1)

Collapse
 
konnorrogers profile image
Konnor Rogers

Nothing super advanced, theres some fancy magic things I could get into, but these are my current git aliases:

# git
alias gaa='git add -A'
alias gdiff='git diff'
alias gcm='git commit -m'
alias gcv='git commit -v'
alias gp='git push'
alias gpu='git push -u'
alias gcob='git checkout -b'
alias gco='git checkout'
alias gm='git merge'
alias gms='git merge --squash'
alias gbr='git branch'
alias gdel='git branch -D'
alias gst='git status'
alias gset='git remote set-url'
alias g-count='git rev-list --count HEAD ^origin'
Enter fullscreen mode Exit fullscreen mode

I think I have a problem.

g-count is so useful for rebasing branches.

git rebase HEAD~$(g-count) -i

For an interactive rebase on the current branch going the number of commits you have backwards.