“Attitude is like a price tag, it decides your value.” This is quite a common quote and truly depicts the meaning of the word “tag”. Tag is not an alien word for any of us. A tag is denoted as a label that works as an additional identifier (or an identifier if there aren’t any). So if I want to tag the great scientist Dr. APJ Abdul Kalam as “missile man” then that is the identifier for him. Next time someone says “missile man“, it is understood what is meant by that.
A tag has a similar meaning in Git and GitHub. Tags help in identifying different commits that are important enough to be identified or be noticed. For example, tagging a commit with release version 3.0 means that commit was the final commit before 3.0 version of the software was launched. It is convenient and easy. GitHub provides a whole different section to look at the tags and analyze them there. In this tutorial, we will look at the same highlights:
- Defining Git Hist Alias in Git.
- Creating Tags in Git.
- Pushing the Local Tags to Remote Repository.
Tags do not look this important but they stand as one of the strongest features in Git and GitHub. Although Git limits the feature to just marking important events or milestones in the project, GitHub has extended this feature to the release versions of the software. This we will see in the later sections of this post. Tags might sound a little different as a concept, so let’s see how we can tag in Git and push the same local tags to the remote repository located in GitHub. But before that, let us quickly learn about aliases in Git.
Git Hist Alias in Git
Alias is a term associated with shortcuts in Git. Alias in Git is used for compressing the longer sequence of commands to a shorter sequence to save time in the future. It is always better to apply aliases to the frequently used longer commands. By longer commands I mean longer patterns of commands which include different options and flags and are also used frequently. It is noteworthy that there is no such command as “alias” that exists in Git. Alias is just the term used to create a shorter command out of a longer sequence of commands. So, since there is no concept as an alias, where do we do all this?
Aliases are done in Git Config file. To know more, you can visit this link about the git config file and how it is viewed and edited in Git Bash. Once the alias is created, the user can then use the aliased name instead of the whole command. It is similar to the alias we created about the remote repository as Origin while cloning. Let’s see how to create an alias for adding graphs and beautifying the git log command.
Open your Git Bash in the working directory. Type the following code and execute the command:
git config –global alias.hist “log –pretty=format:’%h %ad | %s%d [%an]’ –graph –date=short”
alias.hist means that we are creating the alias with the name of hist for the command that follows.
Knowing each component of this command is not yet required. Type git hist now to see if the alias works:
Execute the command by pressing enter.
This way we can create an alias for a command. We will be using git hist in our next section. You can learn about more aliases from Git HowTo and Git Alias.
Creating Tags in Git
Creating Git Tags is very simple. But, the user must be familiar with the Git Log command beforehand. So, if the git log seems new to you, it is advised to read the tutorial about the git log command first.
1.Open Git Bash in the working directory.
2. Check if you have a clean working directory.
3. Execute the following command to view the commits:
git log –oneline
4. We can now create a tag onto any of these commits. Let’s tag the last commit on the dev branch by executing the following command:
git tag ongoing dev
5. Check if the tag was created or not by executing the following command.
git hist
Although, this command will tag the last commit on the branch dev.
For tagging a specific branch, we will make use of the hash code of that particular commit. To list out the commits, let’s execute the git log command once again.
The commit is f030ee9. Let’s tag it with the following command:
git tag -a <tag_name> -m “<Message_for_commit>” <commit_hash_code>
Note: -a here denotes the annotated tags which in layman terms means tags that are specific and not generalized. –m is the flag to tell that the sentence that is followed is the commit message.
Execute the git hist alias command once again and check if the commit we intended was tagged or not.
Here we go! We have tagged the commit successfully. If the intentions of the user are just to view the tags and commits, they can also use the git log –oneline command like as shown below:
Note: Viewing tags like this sometimes depends on the client and operating systems. Sometimes different OS do not show the tag in one line command for previous versions also. So, it is better to use alias only.
The user can also view all the tags in the repository by the following command:
git tag
So, we are all set now by tagging the commits on local machines. But, these commits are not yet visible on our remote repository on GitHub. So, let’s push these tags and see where they are available in GitHub.
Pushing Git Tags to GitHub
Pushing the tags is similar to pushing anything on the remote repository. Follow these steps to push the tags on the remote repository:
1.Open Git Bash in the local working directory.
2. First of all, we have to check that there are no changes on the remote that is not yet synced up with the local machine. This is done through git pull command. (Refer Git Pull Command).
3. Git does not push the tags by the normal git push command. If we use git push as it is, we get the following response:
Git says that everything up-to-date which means there was nothing to push. To push the tags into the remote repository type in the following command:
git push –tags
Press enter to execute the command.
Git says that both of our tags: ongoing and v1.0.1 have been pushed successfully. Let’s verify these on the GitHub repository.
Git Tags in GitHub
To verify the tags that we created in the local repository, visit your GitHub account.
Go to the Git Repository Home page and visit the releases tab on the home page.
In this panel, all the tags will be visible that we just created in our local repository.
This way you can push all the local tags on to your remote repository and view them in your account. But, we are not yet done with the tags. Notice that GitHub named the tab as Releases and tag is just a tab inside Releases. We will see this in the later tutorial. We will continue the discussion in the next tutorial where we will try to delete and play around with the tags on GitHub and understand the term releases with respect to GitHub.