To set up and use Git aliases for common Git commands, follow these steps:
Open a terminal or command prompt.
Enter the following command to open your global Git configuration file in a text editor:
git config --global --edit
[alias]
[alias]
section, define your aliases using the following format:new_alias = original_command
For example, you can define an alias st
for status
command:
[alias]
st = status
Save and exit the configuration file.
Now you can use the aliases you have defined. For example, instead of typing git status
, you can simply enter git st
.
You can also use alias chaining to create more complex aliases. For instance, you can create an alias poh
to execute pull origin HEAD
command:
[alias]
poh = "!git pull origin HEAD"
Note the use of !
before the command, which allows running shell commands.
That's it! You have set up and can now use Git aliases for common Git commands. Feel free to add more aliases or modify them in your global Git configuration file as per your requirements.