Let's Learn About Git Default Branch 📥📤 In Detail

Introduction

 
In my previous article, we have discussed Gitignore with its uses to ignore files without committing to Git or Github. Also, we have discussed the steps to customize the .gitignore file of the GitHub repo and steps to add .gitignore file manually to GitHub.
 
In this article, I will describe the below-mentioned points in detail,

Learn About Git Default Branch 

 
When we create a new repository on GitHub, there is a branch created by default as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 
So, all the developers clone this repository as shown in the above image. They will be connected to the master branch and whatever modifications they do those changes will be committed to this master branch also. In my previous article, I have described the steps to create and manage the Git branch in detail. If I will create a new branch named Satya and after refresh the repository, the branch will be selected as master by default as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Let's see what happens after refreshing the GitHub repository as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Here we can see the master branch is selected as the default branch instead of a new branch called Satya after refreshing the SatyaThreeEmptyRepo GitHub repository. It happens because the master branch is the default branch.
 
Now we check these branch details that I have created along with the default branch master as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details

Steps To Create New Branch As Default Branch 

 
Here I will create a new branch called Development and make this branch the default branch instead of the master branch in this GitHub repository. 
 
Let's Know About Git Default Branch 📥📤 In Details
 
Now go to these branches' details as shown below,
 
Step 1
 
Let's Know About Git Default Branch 📥📤 In Details
 
Step 2
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Step 3
 
Let's Know About Git Default Branch 📥📤 In Details
 
Step 4
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Step 5
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Step 6
 
After these previous steps are completed, we can set our default branch called Development as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Now, we check branch details for checking the default branch as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Also, we can check as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 

Uses Of Default Branch After Cloning The Repository 

 
Let me clone this repository under Development as the default branch using Git Bash as shown below.
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Using Git Bash to clone the repo as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Let's check the default branch using Git Bash.
 
Let's Know About Git Default Branch 📥📤 In Details 
 
Also, we can check the default branch or currently connected branch using a command called git branch as shown below,
 
Let's Know About Git Default Branch 📥📤 In Details
 
So, now all developers will connect this default branch and commit the code to this branch. We have described the steps to move code from one branch to other in my previous article link as given above.  So, in this article, we have 3 branches in the GitHub repository as shown below. 
 
Let's Know About Git Default Branch 📥📤 In Details 
 

Describe The Uses Of These 3 Branches In Short 

  1. Development
    This branch is used for developers to commit code. After successful sanity testing in this branch, the code moved to the Satya branch.

  2. Satya
    This branch is used for testing purposes or QA purposes by the Testing team. After successful testing, the same code moves to the master branch.

  3. master
    Finally, the code moves from Satya to the master branch for deployment purposes to the production/prod server. 
Like above we follow different branching strategies in GitHub. 
 

Summary

 
In this write-up, we have learned the below details,
  • What is git default branch
  • Use of default branch
  • How to change the default branch
  • Check default branch using Git Bash
Thank You & Stay Tuned For More


Similar Articles