How many times a day do you write git add
, git commit -m
and git push
in your terminal? Tons! Wouldn't it be nice if there was a faster way to write out the commands you use every day? Well, there is and it's aliases.
I'll be going over using aliases with Zsh which is now the default shell for Macs using Catalina. Zsh is an extended version of Bash but it has a few additional features and has support for plugins and themes.
Making an Alias
You'll need to open your Zsh configuration file (.zshrc
) and add the following syntax at the bottom of the file to make your alias:
alias [custom-alias]=["command"]
I use Ember at work so I'm constantly writing out the full command to run my tests. Instead of having to write ember test --server --launch=false
every time I've set up the following alias:
alias ets="ember test --server --launch=false"
Now, whenever I want to run my tests I use the command ets
and have saved myself a little bit of time typing!
Oh My Zsh
Another advantage of using Zsh as your shell is that you can install Oh My Zsh which is a framework for managing your Zsh configuration.
You can install Oh My Zsh via curl:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Besides having awesome plugins and themes, Oh My Zsh also includes a ton of git aliases. You can see which ones are available by running alias
. There are a ton of preconfigured aliases and all you have to do is add them to your .zshrc
configuration file.
What's your favorite Git alias? I'd love to know in the comments below!
Be sure to follow me on Twitter for lots of posts about tech, and if I'm being honest, lots of posts about dogs too.
Top comments (9)
I made a couple recently while working on a Rails project.
I have the reload alias because I find myself tweaking my dotfiles frequently while working.
Inspired by Oh My Zsh, there's Oh My Posh for PowerShell. It focuses only on command-line theming (no Git aliases).
github.com/JanDeDobbeleer/oh-my-posh
Combined with posh-git, it provides a very nice experience for Windows users with PowerShell.
I can't live without being able to entirely clear the terminal and its scrollback buffer:
Checking what directories and files are eating your precious disk space is invaluable too, and sorting the output (for GNU, not BSD/Mac):
No need to keep typing
git
all the time when you can just:My long list of git aliases for extreme efficiency, most of which I use daily:
And when you're feeling too lazy to write proper commit messages:
(don't actually do this 😛)
This one formats the git log to be more concise:
ls = git log --pretty=format:"%ci\\ %C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
Delete all branches that were once part of origin, but are no longere there. Any local branches you have made but not pushed will be safe.
prune-branches = git remote prune origin && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs -r git branch -D
What I use for git:
For hugo:
To generate a UUID (universally unique identifier) quickly:
To do an
ls
every time I do acd
:gpod: git pull origin development
grod: git rebase -i development (grod as in "Git Rebase On top of Development"; the "o" is for "on")
(because when working on I team, I always have to remember to get current first...that's easy to forget)
Not super original but I like:
git cm (commit --message)
git pr (pull --rebase)
git ss (stash --save)
git lg (git --log --oneline ???) and other nice options.
my favorite zsh alias is
gpsup
forgit push --set-upstream
After reading this I was interested how to make alias with variable, so I googled it and find out you can use functions since aliases do not support variable.
Put this inside function in your .bashrc or .zshrc file:
To move file.md to documents just use:
Or... you can put the function in an alias: