How to Git Your Code

Nauman Shahid
5 min readOct 9, 2021

--

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.

  • Spring Boot Application from GitHub
  • Download Git

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 commands add and commit create snapshots and restore points

Git makes it easy to create different branches for different development purposes and merge them to release a new version.

Code branches and merger

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

Initialise a git in an empty repository (demo)
  • Add all files to the snapshot: git add ..
Add files to the git snapshots
  • Commit the snapshot: git commit –m “Default demo Spring Boot Application”.
Commit the snapshot
  • You can check the Git’s current status anytime by using the command git status.
Check 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 .
Create a branch develop and switch to the branch
Add files to the git snapshot
Commit the Task-II snapshot
  • Check the commit history: git log
Commit history

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 and git checkout -b newfeature.
Checkout onto newfeature branch
Add files to the git snapshot
Commit the Task-III changes on the branch newfeature
  • Switch back to the branch develop and merge the new feature onto the develop branch: git checkout develop & git merge newfeature .
Switch to develop branch
Merge newfeature with branch develop
  • Check the commit history: git log.
Commit history after adding newfeature branch

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.
Switch to branch master
Merge develop with branch master
  • Check the commit history: git log.
Commit history after adding develop branch to master

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!

--

--

Nauman Shahid
Nauman Shahid

Written by Nauman Shahid

Research scientist, freelance writer, forever curious. Research is my playground, sharing insights is my passion. More about me at https://nshahid.info

Responses (1)