Version control is a cornerstone of modern software development. It helps teams manage changes to their codebase, track different versions, and collaborate effectively. Git is one of the most popular tools for version control, and mastering it can significantly enhance your workflow. In this article, we’ll explore how to use Git for versioning, with a focus on versioning for tools like Grafana and Prometheus.

Getting Started with Git
Before diving into versioning, make sure you have Git installed and configured on your system. Set up your global Git configuration with your username and email:
git config --global user.name "ozk17"
git config --global user.email "ozk17@itu.edu.tr"
Generate an SSH key for secure communication with GitHub:
ssh-keygen -t rsa -b 4096 -C "ozk17@itu.edu.tr"
Add your new SSH key to your GitHub account. This step ensures you can securely push and pull changes to and from your repositories.
Setting Up a New Git Repository
Start by creating a new project and initializing it with Git:
mkdir my-project
cd my-project
git init
Add a new file and commit your changes:
echo "This is only a test" > test.html
git add test.html
git commit -m "Initial commit"
Create a new branch for further development:
git checkout -b feature-branch
Add a remote repository:
git remote add origin git@github.com:ozk17/your-repo.git
git push -u origin master
Versioning with Tags
Tags in Git are used to mark specific points in your history as important. They are often used to mark release versions. Here’s how you can create and push a tag:
Create a Tag:
git tag -a v1.0 -m "Version 1.0"
Push the Tag to the Remote Repository:
git push origin v1.0
Tags help you identify specific releases or milestones, making it easier to navigate through the project’s history.
Versioning Grafana and Prometheus
When working with tools like Grafana and Prometheus, you might want to version your configuration files or Docker images to ensure consistency across environments. Here’s an example of how you can version these tools in a docker-compose.yml
file:
version: '3'
services:
grafana:
image: grafana/grafana:8.0.0
ports:
- "3000:3000"
prometheus:
image: prom/prometheus:v2.30.0
ports:
- "9090:9090"
Updating Versions:
When updating versions, make changes to your configuration file and commit those changes:
git add docker-compose.yml
git commit -m "Updated Grafana and Prometheus versions"
git push origin master
Reverting to Previous Versions:
If you need to revert to a previous version, you can check out a specific commit:
git checkout <commit-id>
To return to the latest version, simply switch back to the master branch:
git checkout master
Conclusion
Versioning is a crucial aspect of managing software projects and tools. By effectively using Git’s versioning features, including tags and commits, you can maintain a well-organized codebase and ensure consistency across different environments. For tools like Grafana and Prometheus, versioning their configurations or Docker images helps in maintaining stability and compatibility.