Use Git with Standard branching approach

Kaushal Vachhani
3 min readMay 22, 2021

If you have recently started using git, then this article is probably for you to understand the most commonly used git branching approach.

What is Git?

Git logo
Source: https://git-scm.com/downloads/logos

Git is primarily an open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. In real-life projects, multiple developers work on the same project, and git is used to ensure that there are no code conflicts between developers.

Download git

Git can be downloaded from the official website of the git: https://git-scm.com/downloads

Once the git is installed in the system, verify the git installation by using the following command.

git --version

Branching Strategy in Git

The branching approach is very important while you are working on a real-time project with multiple developers. There are very high chances of conflict in the codebase if the proper approach is not being followed.

The most common branching approach is that all the developers working on the same project should create their separate ‘feature’ branch and push their developed code over there.

Feature branches allow the work done on the feature to keep away from the common codebase until the completion of the development.

Once the developer completes the feature development, the code will be merged with the ‘develop’ branch. Similarly, all the developers will merge the code with the ‘develop’ branch on completion of their respective feature development.

Once all the feature branches are merged to the develop branch, develop branch can be merged with the ‘master’ branch to reflect code changes in the production environment. (In this scenario, the master branch will be the production branch that contains the production code).

Git commands

Here are the commands that can be followed to apply the above branching approach.

  • Clone the repository in the local system
git clone <clone_url>
  • Create develop branch if it’s not available, check out the branch, and push it to the remote repository.
git checkout -b developgit push -u origin develop
  • Create a feature branch, check out the branch, and push it to the remote repository.
git checkout -b feature/feature1git push -u origin feature/feature1
  • Now, the local repository is pointing at the feature branch. Add the developed code to the feature branch in local.
  • To push the developed code to the remote repository, add the code changes to the staging for the next commit and push the code.
git add <file_names> OR git add .git commit -m <commit_msg>git push
  • Now all the code changes will be available in the feature branch at the remote repository. To merge the code with develop branch, create a pull request with a feature as a source branch and develop as a destination branch.
  • Similarly, once all the feature branches are merged to the develop branch and code is ready to push to the production environment, create a pull request to merge develop branch with the master branch.

Note

Merging the code using the pull request is the safest and recommended option as it allows to put reviewers before merging the code with the targeted branch. Also difference between branches can be seen while approving the pull request.

This was my first try to publish an article on this platform. Let me know the feedback in the comment section.

Till then, Happy Coding…………

--

--

Kaushal Vachhani

Passionate about leveraging cutting-edge technologies to drive impactful solutions, I am a proficient data professional with around 4 years of experience.