Git Alias Workflow
Continuing this article series on Streamlining Workflow, we must include a way to streamline our Git commands. This article uses my own aliases and a GIST for the full list.
TLTR: Want to go straight to the code? The complete alias file I use is available in this GIST.
Alias possibilities
There are a few ways to add aliases to your system, and the natural place to start is in your terminal configuration. In my case, I have a ton of aliases I have added to my .zshrc workflow.
However, since these are Git commands, I have decided to add them to my .gitconfig file. This makes sure my zshrc code is more DRY. To do this, add a new section to your .config title [alias]. Now, let's begin.
My configuration
I am not going to go over every aliased command in my configuration, just the ones I use most frequently.
Branches
I have several commands that help with branches. Each command is prefixed with git.
- So, to check out an existing branch:
git co name-of-branch - Create a new branch:
git cob name-of-new-branch - Create a new branch:
git br name-of-new-branch. This alias I have stopped using in favor ofcobbecause at creation,cobchanges to the branch. - Change to master branch:
git com. If you have changed your default branch tomainor some other name, this will still change to the default branch. - Delete a branch:
git brd name-of-new-branch
Commits
So, to check the status: git st, which uses the -sb switch to trim the CLI to a cleaner output:
## master...origin/master
M content/posts/git-alias-workflow.md
- Add all changed files:
git aainstead ofgit add -A - Commit:
git cmThis will open your editor of choice, or you cangit cm -m "My commit message" - Okay, so my most used alias:
git aacmis an alias forgit add -A && git commit. Remember, you will need to use the-mto add a message.
Remote
This alias is for a combined push with the remote repository:
- Combined add, commit, and push:
git acp, using your editor, or suffix with `-m "Commit message."
Your remote:
- Push after you have done your commit:
git po, as a short alias for `git push origin - Pull from your remote branch:
git ploas an alias forgit pull origin
Working with an upstream
- Fetch:
gitfminstead ofgit fetch upstream.` - Merge upstream with main branch:
git mupas an alias forgit merge upstream/master
Logs
I have a few aliases for git log
Pretty format, with decoration, is git ls:
Pretty format, with decoration and --numstat is git ll:
These are the basic aliases that I use the most. Again, refer to the GIST for a complete list.