0
0
Gitdevops~5 mins

Deployment triggers from tags in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you want to start a deployment only when a specific version or milestone is ready. Using tags in git helps you mark these points and trigger deployments automatically when you create or push these tags.
When you want to deploy only stable versions marked by tags, not every commit.
When you release software versions like v1.0, v1.1 and want deployment to happen on these tags.
When your CI/CD pipeline listens for tags to start building and deploying your app.
When you want to keep your deployment history clean by deploying only tagged releases.
When you want to roll back easily by deploying a previous tag.
Commands
This command creates a new tag named v1.0 on the current commit to mark a release point.
Terminal
git tag v1.0
Expected OutputExpected
No output (command runs silently)
This pushes the tag v1.0 to the remote repository so that the deployment system can detect it.
Terminal
git push origin v1.0
Expected OutputExpected
To https://github.com/example/repo.git * [new tag] v1.0 -> v1.0
Lists all tags in the local repository to verify that the tag was created.
Terminal
git tag
Expected OutputExpected
v1.0
Pushes all local tags to the remote repository at once, useful if you created multiple tags.
Terminal
git push --tags
Expected OutputExpected
To https://github.com/example/repo.git * [new tag] v1.0 -> v1.0
--tags - Push all tags to remote
Key Concept

If you remember nothing else from this pattern, remember: creating and pushing tags lets your deployment system know exactly when to deploy specific versions.

Common Mistakes
Creating a tag locally but forgetting to push it to the remote repository.
The deployment system only sees tags on the remote, so it won't trigger deployment.
Always run 'git push origin <tagname>' or 'git push --tags' after creating tags.
Pushing tags before the commit is ready or tested.
This can trigger deployment of incomplete or broken code.
Make sure your code is tested and stable before tagging and pushing.
Using lightweight tags instead of annotated tags when your deployment system requires metadata.
Lightweight tags have no extra info like author or date, which some systems need.
Use 'git tag -a v1.0 -m "Release v1.0"' to create annotated tags if needed.
Summary
Create a tag to mark a specific commit for deployment.
Push the tag to the remote repository so deployment systems can detect it.
Use 'git tag' to list tags and verify creation.
Use 'git push --tags' to push all tags at once.