Learn to Create Git Aliases using Shell Script

Learn to Create Git Aliases using Shell Script

A Tutorial, on how to create Git Aliases using shell script

1. Introduction

In this short tutorial, we'll cover how to use a shell script to setup Git Aliases. Using aliases will make your experience with Git more enjoyable.

2. Shell Script

You indeed can set up the aliases without using a shell script but, then you have to type the same commands on any system that you're going to use for development.

A shell script allows us to write the commands once to set up aliases, and if we move to a new system, we only have to run the shell script to set up the aliases again.

Create a new shell script and add this to it:

After this your can run the shell script to set up your aliases.

# For Checking out a branch
git config --global alias.co checkout
# For Creating a branch
git config --global alias.br branch
# For Committing 
git config --global alias.ci commit
# For Checking the status of your repo
git config --global alias.st status
# For Resetting the HEAD
git config --global alias.unstage 'reset HEAD --'

3. Use the New Git Aliases

Here are a few examples on how to use the new aliases.

3.1 Checkout a Branch

git br branchName // checkouts the branch

3.2 Create New Branch

git br newBranchName // creates new branch

3.3 Create New Commit

git ci -m 'commit message.' // creates a new commit message 

3.4 Reset HEAD

git unstage // resets HEAD

4. Conclusion

In this short tutorial, we'll learn how to set up Git aliases with a Shell Script and how to use the new aliases.

Did you like it? Why don't you try also...

Quickly Spin Up MongoDB With Docker Compose

Quickly Spin Up MongoDB With Docker Compose

Learn How to Install MongoDB Using Docker Compose

Is String a Palindrome?

Is String a Palindrome?

Learn How to Test if a String is a Palindrome in Go.

How to Convert GoLang Integer to String Conversion

How to Convert GoLang Integer to String Conversion

Learn how to convert integers to strings and how to convert strings to integers in GoLang