8 Git aliases that make me more efficient
Sun Jan 05 2025 Pin
473 words · 3 minutes

8 Git aliases that make me more efficient


Table of Contents

Use aliases to create shortcuts for your most-used or complex Git commands. Defining Git aliases to serve as substitutes for commands provides two major benefits:

  • It simplifies long commands that have many options, making them shorter and easier to remember.
  • It shortens frequently used commands so that you can work more efficiently.

How to define and use aliases Link to How to define and use aliases

To define a Git alias, use the git config command with the alias and the command you want to substitute. For example, to create the alias p for git push:

BASH
1
git config --global alias.p 'push'
BASH
1
git p

You can use an alias by providing it as an argument to git, just like any other command: To see all your aliases, list your configuration with git config:

BASH
1
2
3
4
git config --global -l
user.name=ricardo
user.email=ricardo@example.com
alias.p=push

You can also define aliases with your favorite shell, such as Bash or Zsh. However, defining aliases using Git offers several features that you don’t get using the shell. First, it allows you to use aliases across different shells with no additional configuration. It also integrates with Git’s autocorrect feature, so Git can suggest aliases as alternatives when you mistype a command. Finally, Git saves your aliases in the user configuration file, allowing you to transfer them to other machines by copying a single file.

Regardless of the method you use, defining aliases improves your overall experience with Git. For more information about defining Git aliases, take a look at the Git Book.

8 useful Git aliases Link to 8 useful Git aliases

Now that you know how to create and use an alias, take a look at some useful ones.

1. Git status Link to 1. Git status

Git command line users often use the status command to see changed or untracked files. By default, this command provides verbose output with many lines, which you may not want or need. You can use a single alias to address both of these components: Define the alias st to shorten the command with the option -sb to output a less verbose status with branch information:

BASH
1
git config --global alias.st 'status -sb'

If you use this alias on a clean branch, your output looks like this:

BASH
1
2
git st
## master

Using it on a branch with changed and untracked files produces this output:

BASH
1
2
3
4
git st
## master
 M test2
?? test3
BASH
1
git config --global alias.ll 'log --oneline'
BASH
1
git config --global alias.last 'log -1 HEAD --stat'
BASH
1
git config --global alias.cm 'commit -m'
BASH
1
git config --global alias.rv 'remote -v'
BASH
1
git config --global alias.d 'diff'
BASH
1
git config --global alias.dv 'difftool -t vimdiff -y'
BASH
1
git config --global alias.gl 'config --global -l'
BASH
1
git config --global alias.se '!git rev-list --all | xargs git grep -F'

sourcelink: https://opensource.com/article/20/11/git-aliases

Thanks for reading!

8 Git aliases that make me more efficient

Sun Jan 05 2025 Pin
473 words · 3 minutes

© EveSunMaple | CC BY-SA 4.0