DEV Community

Cover image for Adding Command alias in your Gitbash
Ashish Prajapati
Ashish Prajapati

Posted on

Adding Command alias in your Gitbash

Adding alias in your Gitbash terminal can help you speed up your workflow when using the terminal. ⚑️

In this tutorial, I am going to guide you how you can configure the aliases for your day-to-day commands. πŸš€

First of all open the Gitbash and type following command in it.

alias
Enter fullscreen mode Exit fullscreen mode

And you will see an output something like below image. It will give the list of aliases which are configured. πŸ“‹

Image description

If you see nothing, then no aliases are set. So don't worry. πŸ˜…

To set the alias for any command type following in the terminal. ✨

alias new_command_name='old_command_name'
Enter fullscreen mode Exit fullscreen mode

Image description

The alias set within the image will create an alias for git commit. Now I can just type gc -m <msg> and it will commit my code. 🎯

And that's it, you have configured your first alias. Hurray!!! 🎊

Hold on, it's not over yet. ⚠️ If you just close the terminal and try to re-run that alias again, it will throw error like this. 😱

Image description

What?! You will think I just set it and now it's gone. Yup it's gone. πŸ’” Because aliases set with alias are session based means they are deleted once the terminal is closed off.

So how can we make it permanent??? πŸ€”

Well, there is a way make it permanent. πŸ’‘ It's .bash_profile file, it's location differ from OS to OS. For windows it would be OS_Drive/Users/<your_user_name> and for ubuntu it's present in root and you can run ls -la to see it. πŸ“

Image description

Open the .bash_profile file and edit it. ✏️
Just add the following line of snippet in that file. Do not remove anything from that file, just go to very end of it and insert new line and copy-paste. ⚠️

Congratulations. You have created your first permanent alias, I repeat first permanent alias of your. πŸ†

Now you can configure as much as aliases you want, and you just need to add them within .bash_profile file. πŸ”§βœ¨

Top comments (0)