Git - tags

git Tags -Example


 Tags are used for defining the version or release of your code.


Prerequisites:- Local git repo should be created and have some files in it.

Branch:- working on the main branch


Step1:- Switch to the main branch

             git checkout main

Step2:- Consider the code which is in the main branch is the first to release code, so let's tag it with version v1.0 ( need to define the tag)

             git tag   # show all the tags

             git tag v1.0

             git tag # it will show v1.0

Step3:- Create some db files(emp.db, company.db) and commit it and these files will be part of the second release, so we need to define one more tag for this release.

           touch emp.db company.db

           git add -A

           git commit -m "db files has been added"

           git tag V2.0

           git tag # show all the tags

Step4:- Create some dependencies files( junit.dep,sel.dep) into your project and make the part minor release of the second version.

           touch junit.dep sel.dep

           git add -A

           git commit -m "dependencies files has been added"

           git tag V2.1

           git tag

Step5:- Display all the files which are released in V1.0 ( it should not show db and dep files)

            git checkout V1.0

            ls

Step6: Display all the files which are released in V2.0 ( it should show db files along with V1.0 files but should show the dep files)

           git checkout V2.0

           ls

Step7: Display all the files which are released in V2.1 ( it should show all the files)

           git checkout V2.1

           ls

Step 8: Push a V1.0 tag to remote repo (Gitlab/Github)

          git push origin V1.0

Step 9: Push all the tags to the remote repo

          git push --tags

Step10:- Check remote Repo (Gitlab/Github) and you will find the tag files in the tags section and if you want you can download those releases or you can edit the release notes and if these releases are not required on remote repo then you can delete it.

Step11:- Let's delete the tags in local repo

             git tag -d V2.1   # To delete V2.1 tag.

             git tag -d `git tag | grep -E '.'` # to delete all the tags 

Comments