How to Git Your Code
Git is a tool used to manage branching, merging, and maintaining code versions.
Overview
This tutorial demonstrates how to build a simple workflow with different branches of development in the product development process. The tutorial shows how to branch, merge, and maintain different versions of the code by using Git as a version control tool.
Tools Preparation
Download and install the following tools.
Git is a free and open-source tool for managing files and keeping track of code changes. You can find detailed instructions for installing Git here.
Background Knowledge
By using the command git add
, we can add all files we want to track into a snapshot. The git commit
command saves the snapshot list so that we can get a list of restore points in the future if we need to go back.
Git makes it easy to create different branches for different development purposes and merge them to release a new version.
We can branch, merge, and check out using git branch
, git merge
, and git checkout
commands.
Task-I: Prepare Spring Boot Application and initial git
- Follow the steps given in “How to Make an Application Using Spring Boot (Server-side)” to build Task-I.
- Initialise a git project with branch master:
git init
.
- Add all files to the snapshot:
git add .
.
- Commit the snapshot:
git commit –m “Default demo Spring Boot Application”
.
- You can check the Git’s current status anytime by using the command
git status
.
Task-II: Complete the request handling on develop branch
We can implement the request handling function as the core function on branch develop by the following steps:
- Create a branch develop and switch to it:
git branch develop
&git checkout develop
.
- Follow the steps in How to Make an Application Using Spring Boot (Server-side)” Task-II.
- Similar to Task-I, add all files to the snapshot and commit the change.
- Check the commit history:
git log
Task-III: Add port configuration on newfeature branch
If a new feature is requested, developers can try implementing it on a branch feature.
- Add a new branch newfeature based on develop to add new features and checkout on the new branch:
git checkout develop
andgit checkout -b newfeature
.
- Follow the steps in How to Make an Application Using Spring Boot (Server-side)” Task-III to modify configuration for ports.
- Add all files then commit the change.
- Switch back to the branch develop and merge the new feature onto the develop branch:
git checkout develop
&git merge newfeature
.
- Check the commit history:
git log
.
Task-IV: Merge develop branch back to master branch for release
- Switch back to branch master and merge branch develop:
git checkout master
&git merge develop
.
- Check the commit history:
git log
.
Conclusion
Git facilitates agile development due to its branching capabilities. It provides developers with an isolated environment for each single change they make to production code. In fact, Git has much more functionality than local version control systems. It is possible to set up remote repositories, pull and push to sync and collaborate with others on the same project.
You can find all the code files for Tasks I, II, and III at GitHub and explained in the tutorial How to Make an Application Using Spring Boot (Server-side).
Thanks for reading! If you enjoyed this piece, a quick 👏 would mean the world to me. Stay in the loop by subscribing to my profile and don’t hesitate to comment or reach out. Happy reading!