Sitemap

CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

My Favorite Git Aliases

3 min readApr 8, 2022

Today it is quite common to be using or have used Git for version control when it comes to Software Engineering. It can get repetitive to type out the full git instructions day in and day out and so shorthand or aliases are common for these commands.

Press enter or click to view image in full size
Photo by Roman Synkevych 🇺🇦 on Unsplash

Here are a few that I immediately setup anytime I am working with another developer or am setting up a new machine. Typically I use Z shell and these will go at the bottom of my .zshrc file in my home directory.

Alias #1

alias ga='git add'

The number of times you need to add a file to git is VERY high so being able to type ga . instead of git add . saves me a lot of time. Alias it this way and save yourself many keystrokes in your workday.

Alias #2

alias gap='git add -p'

This utilizes an interactive prompt to allow you to split changes down into individual commits. When you enter this mode you will be prompted for each chunk of changes in each file. If you enter ? then you can see the list of options.

Stage this hunk [y,n,a,d,/,j,J,g,e,?]? ?
y - stage this hunk
n - do not stage this hunk
a - stage this and all the remaining hunks in the file
d - do not stage this hunk nor any of the remaining hunks in the file
g - select a hunk to go to
/ - search for a hunk matching

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web
Already have an account? Sign in
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Andrew Courter

Written by Andrew Courter

Manager of Software Engineering. Writes on Neovim, programming, and building great software. https://andrewcourter.com

Responses (1)

Write a response

alias current_branch="git symbolic-ref --short HEAD'"
should work as well.