Learn how to mark releases with Git tags in GitHub Actions
Git tags are a powerful way to mark specific points in the repository history, such as stable releases or milestones. Using Git tags in GitHub Actions allows you to create, update, and manage tags as part of your CI/CD workflows.
Here are the steps to follow while creating Git Tags in GitHub Actions.
1. Creating a Git Tag
You can create a Git tag in your GitHub Actions workflow using the git command to tag a specific commit or branch.
Example Workflow for Creating a Git Tag
xxxxxxxxxx171nameCreate Git Tag2on3 push4 branches5main6jobs7 create-tag8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameCreate Git Tag13 run14 git config --local user.name "Your Name"15 git config --local user.email "you@example.com"16 git tag -a v1.0.0 -m "Release version 1.0.0"17 git push origin v1.0.0In this example:
A tag v1.0.0 is created and pushed to the remote repository after a successful commit or push to the main branch.
2. Updating an Existing Tag
You can update or modify existing tags by using the git tag -f command or by rewriting history, followed by pushing the updated tags.
Example Workflow for Updating a Tag
xxxxxxxxxx171nameUpdate Git Tag2on3 push4 branches5main6jobs7 update-tag8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameUpdate Git Tag13 run14 git config --local user.name "Your Name"15 git config --local user.email "you@example.com"16 git tag -f v1.0.0 -m "Updated release version 1.0.0"17 git push origin v1.0.0In this workflow:
The existing tag v1.0.0 is force-updated with a new commit message.
3. Using Git Tags with Releases
Git tags can also be associated with GitHub Releases, making it easier to manage release artifacts alongside version control.
Example Workflow with Git Tag and Release
xxxxxxxxxx231nameRelease with Git Tag2on3 push4 branches5main6jobs7 release8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameCreate Git Tag13 run14 git config --local user.name "Your Name"15 git config --local user.email "you@example.com"16 git tag v1.0.0 -m "Release version 1.0.0"17 git push origin v1.0.018nameCreate GitHub Release19 usesactions/create-release@v220 with21 tag_namev1.0.022 release_name"Release v1.0.0"23 body"This is the first release."In this workflow:
A Git tag is created, and then a GitHub Release is associated with that tag.
4. Using Git Tags with Workflow Versioning
Tags can be used for version control within your workflows to identify specific builds and deployments.
Example: Using Tags in Workflows
xxxxxxxxxx131nameDeploy with Versioned Tag2on3 push4 tags5v1.6jobs7 deploy8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameDeploy to Production13 run./deploy.shHere, the workflow only triggers deployments when the tag matches a specific pattern, e.g., v1..
5. Deleting Git Tags
You can delete Git tags via Git commands in workflows if necessary.
Example: Deleting a Git Tag
xxxxxxxxxx151nameDelete Git Tag2on3 workflow_run4 workflows5Create Git Tag6jobs7 delete-tag8 runs-onubuntu-latest9 steps10nameCheckout Repository11 usesactions/checkout@v312nameDelete Git Tag13 run14 git tag -d v1.0.015 git push origin --delete v1.0.0Best Practices for Using Git Tags in Actions
Consistent Naming: Use meaningful tag names (e.g.,
v1.0.0,release-2024.12).Automation: Use Git tags as a versioning mechanism for continuous integration pipelines.
Push & Sync: Ensure tags are consistently pushed to both local and remote repositories.
Documentation: Document tagged releases for better traceability.






















Leave a Reply