Example 01: Linux Alias
Let’s get started with the implementation of making an alias for different commands used in the Linux system while working in the Kali Linux system. So, the “pwd” command has been used here to show us the current working directory of git Linux which we are working on right now.
It’s time to make the alias for making a shortcut command for the original large commands for our use and ease. Let’s say we want to create an alias for the “pwd” instruction of Linux. Thus, we need to use the “alias” instruction for this purpose. We have been using the “alias” keyword followed by the short alias command “p” we want to use as an alternative to the “pwd” instruction. The “pwd” instruction or the original instruction must be mentioned within the single quotes after the “=” sign. The alias for the “pwd” command has been created as the “p” instruction. After using the “p” instruction, it works the same as the “pwd” instruction.
$ p
Example 02: Bash Git Alias
Let’s have a look at creating an alias for git commands that are most used in the terminal of Kali Linux. To create an alias in Git bash, we need to use the “git config” command followed by the “—global” option, an alias to be created, and an original git command in a single instruction. The most used git bash command is the “git push” instruction that is mostly used to push the updates and data to the Git hub repository from the local system. So, we will be creating an alias for the “push” command using the “git config” instruction followed by the “—global” option. The alias will be created by using the keyword “alias” followed by a dot and the command, i.e., “p” as shown in the attached image. Now, you can use the “p” command instead of “push” in the git terminal to push your updates to the GitHub remote repository.
You can use the “git config” command followed by the keyword “global” and the “-l” flag to list all the configurations we have made to our git at the local computer. It will show you the username, email, and password that you have configured at your local git repository to access the remote GitHub repository. After that, you can see the alias we have just created for our git in Kali Linux. This means you can use the “p” instruction as an alternative to the “push” query.
To observe modified or untracked directories, Git cli users frequently utilize the status query. This query generates a lot of lines of output that we might not want. To handle these elements, we could use an alias. To display a far less verbose result with branch details, specify the alias “st” as an alternative to the “status –sb” instruction. After using the git “st” instruction, we have got the information regarding the master branch status as displayed.
$ git st
Within git bash, we tend to use the “log –online” instruction to see all the commits done by a specific user. Thus, we will be making an alias for this command as “ll” using the same got config instruction presented in the image. After using the alias “ll” we have found that there have been no commits yet that are being made by a current user to GitHub remote repository.
$ git ll
The Git bash came up with the “log -1 HEAD –stat” instruction to display the very last commit from your system to the GitHub repository. So, we have been making a git alias for this command as the “last” command shown in the git config query displayed in the image.
After using this alias as an alternative to the “log -1 HEAD –stat” instruction, the last commit done by a specific git user from this bash CLI has been displayed, i.e., a folder has been deleted.
When we tend to save the changes done by a git user, we often use the “git commit” instruction along with its “-m” option to display a message. Let’s create an alias for this command as “cm” via the git config instruction shown in the image. After that, we used this newly made alias command “git cm” along with a simple message. This made all the changes and updates tracked at our end.
$ git cm “Commit Successful”
We use the “remote –v” instruction in git to display the list of all the already installed remote libraries at our git bash. We have created an alias “rv” for this instruction as below. After using this alias as a git instruction, we have got the same output as we usually get for the “remote –v” instruction.
$ git rv
Conclusion
This is all about using aliases in git bash while using the Kali Linux system. We have tried to make an example for a simple bash alias first. After that, we discussed different git commands and the git config instruction to make an alias for those commands in git bash.