Git alias

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 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.
      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
    4. Then the alias will be visible.
      c = commit
    5. Now the alias is accessible. It will work just as you typed the whole command.
      git c -m "example"
    6. In the end, open the config file and you will see something like this.
      [alias]
      c = commit
  • Creating git aliases by directly editing .gitconfig file

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

    [alias]
    co = checkout



Do you find this helpful?

Related articles