Git has the ability to basically create commands that work well along with git and these commands can be an alias for another command, including passing parameter also.
Let's start with my projects folder and cd into my Git repository, my case it is starter-web-1/ folder so do
cd starter-web-1/, If you do an
ls, you can see all the files which are part of this project and check
git status, it tells our working directory is clean.
Let's start with creating an alias, I will pass the command
git log --all --global --decorate --oneline which displays the clear history of all my commits in my git repository.
So here we have to type long whenever we want this particular output, instead of this, we can create our own command called alias, where it will give exactly the same output but with the shorter command.
Let's see how to create it, here I will use hist as my alias, where it does not create yet, if I pass
git hist Git replies that it's not a Git command and it tries to help out with some suggestion.
So to create my own command, am using Git's config command
git config --global, Because we want this alias to be available regardless of Git repository and hence it will be stored at the user level.
So basically any configuration setting that starts with alias will allow us to create an alias, so will pass the command
git config --global alias.hist "log --all --graph --decorate --oneline" and press enter.
git hist, if you are successful then you should have the exact output, as shown above, let's show you where the alias is stored so that you can modify them if in case you need to.
We will use Git's config command to store the aliases, we need to open the .gitconfig file in our user home directory
notepad++ ~/.gitconfig and press enter.
git histyou can see there are no asterisks and graph lines are present.