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...

Get The Names Of All The Files Inside A Directory Using GoLang

Get The Names Of All The Files Inside A Directory Using GoLang

Learn how to get list all the file names inside of a directory using golang

Is String a Palindrome?

Is String a Palindrome?

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

Using Makefiles For Go (GoLang) Development

Using Makefiles For Go (GoLang) Development

Learn how to run, build and, compile Go (GoLang) Applications for any Platform and Operating System using a Makefile