How to Create Git Aliases (shortcuts) in Gitconfig (macOS)

You don’t want to waste time manually typing out long commands every time you use Git version control.

Let’s turn this common command:

git push origin master

Into this:

git pom

If you don’t have a .gitconfig already, open up your Terminal and run this command:

touch ~/.gitconfig

You should now have an empty .gitconfig file at /users/youraccount/.

Open .gitconfig

Now open your .gitconfig file with this command:

open ~/.gitconfig

You might already have some configuration in this file, such as:

[user]
  email = youremail@gmail.com
  name = John
[github]
  user   = username

If you don’t, I suggest you add it to your gitconfig file now (using your own information).

Create git alias

Now let’s create a git alias for git push origin master.

Move to a new line and add this:

[alias]
  pom = push origin master

Your .gitconfig file should look similar to this:

[user]
  email = youremail@gmail.com
  name = John
[github]
  user   = username
[alias]
  pom = push origin master

Now when you run git pom in your Terminal, it will automatically run push origin master for you.

Make more git aliases

You can use this blueprint to create all types of alias/shortcut commands for Git. For example, let’s say you want to use git s instead of git status. Simple, just add it below your other aliases:

[user]
  email = youremail@gmail.com
  name = John
[github]
  user   = username
[alias]
  pom = push origin master
  s = status

Less typing is always good!


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on