Git Tags .FTW
Tags: git, codequality, vscode, tutorial
Published: 2020-07-28 17:31:25

How they make life simpler

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/r8dplmbvkx1lz5xoai67.png)

<h4>Tagging</h4> 
is an additional mechanism used to create a snapshot of a Git repo. Typically, it is used to create semantic version number identifier tags like `release-20.0.7` ;) that correspond to software release cycles.
Basically = A fixed point in git commit history

<i>Eg: I want to migrate my existing financial statements microservice project from h2 -> mongodb, how can I have the current fully functional h2 version for future
</i>
<br/>

**Solution** : <i>make a tag from the current version of my project</i>

## Type of Tags
1. Lightweight version and mostly good for private projects like mine (they don’t have any message or info like who did what)
   `➜ git tag v0.2`

2. Annotated version has message like commit and can have more info, simply put — metadata
   `➜ git tag -a v0.2 -m “working h2 version of app”`

   If you don’t use `-m`, a text editor will open up where you can enter your required info<br/>

   By default git tag takes the current head as fixed point in time, but you can have your own commit as the point like this

   `➜ git tag -a v1.2 15027957951b64cf874c3557a0f3547bd83b3ff6`

   Also, it's possible to overwrite the tag just like world burning `push -f` command

   `➜ git tag -a -f v1.2 15027957951b64cf874c3557a0f3547bd83b3ff6`

<i>preferred : annotated</i>

## How to push tags

    ➜ git push origin v0.1

## How to fetch tags

    ➜ git pull

Or if the remote tags are not available try

    ➜ git fetch --all --tags

## How to checkout tags to our own branch

    ➜ git checkout -b my-version tags/v0.1

- points to this tag in my new branch 'my-version

# List all tags in your repo

    ➜ git tag

Also you can filter on it with

    ➜ git tag -l `*basic`

- all tags having basic in them

## Finally, delete a tag

    ➜ git tag -d v0.1 (locally)

or

    ➜ git push --delete origin v0.1 (from remote)`

<br/>

**A Complete Example:**

```
➜ git:(master) git tag -a v0.1
➜ git:(master) git push origin v0.1
Counting objects: 1, done.
Writing objects: 100% (1/1), 270 bytes | 270.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/xxxxxx/xxxxxx.git
* [new tag] v0.1 -> v0.1
➜ git:(master)
```

### Bonus

#### 1. You retrieve multiple tags from your remote repository. Then, retrieve the latest tag available by using the “git describe” command.

```
➜ tag=$(git describe — tags `git rev-list — tags — max-count=1`)
➜ echo $tag
v0.2
```

#### 2. Inspect the state of your branch

`➜ git log — oneline — graph`

```
- b5c0345 (HEAD -> my-version, tag: v1.0-rc, tag: v0.2, tag: v0.1, origin/master, origin/HEAD, master) queryDSL example
- 043a12c TextIndexed updated for Spring 2.3+
- f9e007a projection and aggregation
- 48d59eb mongo query dsl — refer README
- a59e6ca controllers with mongo template and mongorepository
- 9e6a36d init
- bfa47c0 Initial commit
(END)
```

If you found this concise and helpful, do support with like 😊

Reference:
https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-tag
<br/>

<p>
Saurabh Kumar<br/>
Coder. Blogger. Mentor. Speaker.

Find more article from me @ <br/>
[<img src="https://img.shields.io/badge/medium-%2312100E.svg?&style=for-the-badge&logo=medium&logoColor=white"/>](https://medium.com/@saurabhk15)

Or checkout my photography @ <br/>
[<img src="https://img.shields.io/badge/instagram-%23E4405F.svg?&style=for-the-badge&logo=instagram&logoColor=white"/>](https://www.instagram.com/saurabh_kr/)