Git and GitHub
Version Management and Release Deployment
In this module, we will learn about version management and release deployment in projects managed with Git and GitHub. Version management helps to tag and track specific versions of your project, while releases provide a formal way to package and distribute your software.
Version Management
What is a version?
A version is a snapshot of your project at a specific point in time. Versions are typically tagged with semantic version numbers, like v1.0.0
, v1.1.0
, v2.0.0
, etc. Semantic versioning follows the pattern: MAJOR.MINOR.PATCH
Tags
Tags in Git are references that point to specific points in the history, usually used to mark release versions.
Create a tag
You can create a lightweight tag or an annotated tag.
-
Lightweight tag:
bash -
Annotated tag:
bash
View existing tags
To list all tags in your repository:
bash
View information about a tag
To see the details of an annotated tag:
bash
Share tags with the remote repository
To push tags to the remote repository:
bash
To push all tags:
bash
Release Deployment on GitHub
What is a release?
A release on GitHub is a packaged version of your code that you can make available to users. It includes the source code, release notes, and optionally, precompiled binaries.
Create a release
- Go to the repository on GitHub.
- Navigate to the "Releases" tab.
- Click "Draft a new release".
Fill out the release information
- Tag version: Select an existing tag or create a new one.
- Release title: Provide a descriptive title.
- Description: Detail the changes in this release (can include a changelog).
- Attachments: Optionally, upload precompiled binaries or relevant files.
- Click "Publish release" to publish the release.
Changelog
What is a changelog?
A changelog is a record of all notable changes in each version of your project. It is a valuable way to communicate improvements, fixes, and new features to users and contributors.
Maintaining a changelog
You can maintain a changelog manually in a CHANGELOG.md
file and update it with each new version:
markdown
Practical Example
Create a tag for a new version
-
Create an annotated tag:
bash -
Push the tag to the remote repository:
bash
Create a release on GitHub
- Go to the "Releases" tab in the GitHub repository.
- Click "Draft a new release".
- Select the previously created
v1.0.0
tag. - Fill out the release title and description.
- (Optional) Add attachments.
- Click "Publish release".
Release Automation
Using GitHub Actions to automate releases
You can set up GitHub Actions to automate the creation of releases. Here’s an example of how to do it with a YAML file.
- Create
.github/workflows/release.yml
:yaml
Best Practices
- Semantic Versioning: Follow semantic versioning for tagging your versions.
- Update Changelog: Maintain and update a changelog with each new release.
- Automation: Use GitHub Actions or similar tools to automate the release creation and deployment process.
- Release Notes: Provide detailed release notes that clearly summarize the changes made.
Additional Tools
semantic-release
semantic-release
is a tool for automating version management according to semantic versioning conventions. It publishes, creates, and updates release notes automatically.
To install and set up semantic-release
:
-
Install
semantic-release
:bash -
Add a configuration file
.releaserc
at the root of the project:json
With these techniques, you can effectively manage versions and release deployments using Git and GitHub. In the next module, we will conclude the course with best practices in Git and GitHub.
- Introduction to Git and GitHub
- Installation and Configuration of Git
- Version Control Fundamentals
- Repository Creation and Cloning
- Making Commits and Tracking Changes
- Branch Management (branching)
- Branch Merging (Merging)
- Conflict Resolution
- Collaborative Work on GitHub
- Pull Requests and Code Reviews
- Advanced Git Usage (rebase, cherry-pick, etc.)
- Automation with Git hooks
- Continuous Integration with GitHub Actions
- Version Management and Release Deployment
- Conclusions and Best Practices in Git and GitHub