Skip to content

git alias

gitalias

Description

A git alias, also known as a shortcut, creates short commands mapping the longer ones. It demands fewer keystrokes to run a command, which simplifies the developers’ work. Direct git alias command doesn’t exist. This type of command is created through the git config command and the git configuration files. Aliases can be generated in a local or a global scope with other configuration values.

Creating Aliases with Git

There are two ways of creating Git aliases: using the git config command and directly editing the .gitconfig file.

  • Creating Git aliases with git config command

    In order to create Git aliases with the git config command, follow the steps below:

    1. To create a git alias you have to edit your .gitconfig file in the user directory, in order to make these aliases accessible for all the projects.
    2. Run the git config command and define the alias.

creating alias in git

bash
git config --global alias.c commit
3. After this the line below will be added to the ~/.gitconfig file. Make sure it was saved.

git config --list

bash
git config --list
4. Then the alias will be visible.

git alias

bash
alias.c=commit
5. Now the alias is accessible. It will work just as you typed the whole command.

git alias example

bash
git c -m "example"
6. In the end, open the config file and you will see something like this.

git alias in .gitconfig

bash
[alias]
c = commit
7. ### Creating git aliases by directly editing .gitconfig file

    The second way of creating git aliases is directly editing git config files, like this:

git alias in .gitconfig file

bash
[alias]
co = checkout

Aliases for Git Commands

Here are some useful git aliases that just replace the original git command and are designed to make you type less:

AliasesDescription
cob = checkout -bCreates and checks out a new branch.
f = fetch -pFetches from a repository and prunes any remote-tracking references that no longer exist on the remote.
p = pushPushes changes to a remote.
bd = branch -dDeletes a branch only if it has been merged.
ba = branch -aLists both remote-tracking and local branches.
bD = branch -DForces deletion of a branch.
dc = diff --cachedDisplays the staged changes.

Practice

What is the correct method to create a Git alias for the 'commit' command using the 'git config' command?

Dual-run preview — compare with live Symfony routes.