Table of content

Setting up alias within Git

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.
GA-ls-git-status

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.
GA-multiple-commands

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.
GA-git-hist

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.
GA-global-alias

Now try 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.
GA-notepad-alias

  • So it will open up a .gitconfig file and all aliases will be listed under the alias section of gitconfig.
  • So now I will modify this, by removing -- graph, save and then exit.
    GA-modified-notepad
  • Now if you do git hist you can see there are no asterisks and graph lines are present.
    GA-git-histtwo
  • And am going to edit the file again and I will add --graph, save and exit and hence you will get back to the old one.
    GA-after-modification
    GA-last-step

Stashing Untracked File in Git

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions