Wednesday, April 27, 2022

Removing Tag(s) From A Git Repository

 If you work on a team that is constantly developing their code, then you are probably dealing with at least one repository that gets periodically tagged (such as when a code release is performed).  If that is the case, then you have probably (or not) had to deal with setting the tags that get applied to the repository.  

If so, then you would be able to see the tags on a repository with the following command:

   $ git tag

If you are looking for a tag, but you only know part of it, you can certainly use grep to weed through the potentially large list of tags that will be presented to you.  Now, if you happen to set a tag incorrectly, or apply it to the wrong repository (or branch of that repository, for instance), you are not stuck.  You can remove it.  Here are the steps:

  1. First, ensure you are in the repository in question and in the correct branch, then do a 'git pull' to ensure you are at the latest change
  2. Run 'git tag | grep <tag>' to get the tag name you need to remove
  3. Run 'git tag -d <tag_name>'        <--- This will remove the tag in your local repository
  4. Run 'git push --delete origin <tag_name>'    <--- This will remove the tag from the remote repo
  5. Run 'git pull'
From here, you will need to run the 'git tag' command in step 2 and verify that the tag has been removed locally.  You can also then go up to GitHub, Gitlab, etc, and check the repository and ensure that the tag has been removed there as well.   

No comments:

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.