HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptTip

Customize Git using aliases for common operations

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
operationscommongitcustomizeusingaliasesfor

Problem

Git allows you to create aliases for many common operations, making it easier to remember and execute them. As far as customization goes, this is one of the most powerful features Git offers, allowing you to create shortcuts for complex commands or to make your workflow more efficient.
Simply running git config --global alias.<alias> <command> will create an alias for the specified command. The alias can then be used in place of the command when running Git commands. If your command contains spaces, you can wrap it in quotes.
Alternatively, you can edit the configuration file and add multiple aliases all at once. This can be the more practical solution for adding more complex commands, as you don't have to worry about escaping special characters.
Below you can find a list of aliases I've found personally useful for increasing productivity when working with Git. Feel free to use them as they are or modify them to suit your needs.
```properties title="~/.gitconfig"

Solution

# Syntax: git config --global alias.<alias> <command>

git config --global alias.co checkout
# Creates an alias `co` for the `checkout` command

git config --global alias.cm "commit -m"
# Creates an alias `cm` for the `commit -m` command


Alternatively, you can edit the configuration file and add multiple aliases all at once. This can be the more practical solution for adding more complex commands, as you don't have to worry about escaping special characters.
Below you can find a list of aliases I've found personally useful for increasing productivity when working with Git. Feel free to use them as they are or modify them to suit your needs.
```properties title="~/.gitconfig"
[alias]
co = checkout
cob = checkout -b

Code Snippets

# Syntax: git config --global alias.<alias> <command>

git config --global alias.co checkout
# Creates an alias `co` for the `checkout` command

git config --global alias.cm "commit -m"
# Creates an alias `cm` for the `commit -m` command
# Syntax: git config --global -e

git config --global -e
# Opens the global git configuration file in the default git text editor

Context

From 30-seconds-of-code: aliases

Revisions (0)

No revisions yet.