Fetch and Check git tag
In the previous step, we saw how to list remote tags without cloning the repository. Now, let's learn how to fetch those tags into our local environment and view them.
To fetch tags from a remote repository, we use the git fetch
command with the --tags
option. This command downloads the tags from the remote repository but doesn't merge them into your local branches.
First, let's create a new directory and initialize a Git repository there. This will be our local workspace.
cd ~/project
mkdir git-tags-demo
cd git-tags-demo
git init
Now, let's fetch the tags from the Git project's repository. We need to specify the remote URL.
git fetch --tags https://github.com/git/git.git
You will see output indicating that Git is downloading objects and processing references. This might take a moment depending on your internet connection.
remote: Enumerating objects: XXXX, done.
remote: Counting objects: 100% (XXXX/XXXX), done.
remote: Compressing objects: 100% (XXXX/XXXX), done.
remote: Total XXXX (delta XXXX), reused XXXX (delta XXXX), pack-reused XXXX
Receiving objects: 100% (XXXX/XXXX), XXX.XX MiB | XX.XX MiB/s, done.
Resolving deltas: 100% (XXXX/XXXX), done.
From https://github.com/git/git.git
* [new tag] v2.0.0 -> v2.0.0
* [new tag] v2.0.0-rc0 -> v2.0.0-rc0
... (many more lines)
After the fetch is complete, the tags are now available locally. To view the tags that you have fetched, you can use the git tag
command.
git tag
This command lists all the tags in your local repository. Since we just fetched the tags from the remote, you should see a long list of version tags.
v2.0.0
v2.0.0-rc0
v2.0.0-rc1
v2.0.0-rc2
v2.0.1
... (many more tags)
You can scroll through the list to see the different tags that were fetched. Press q
to exit the tag list view.
By fetching tags, you now have local references to specific points in the remote repository's history, even though you haven't cloned the entire project. This is a useful way to get access to release versions or other important milestones.