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,
- What is git default branch
- Use of default branch
- How to change the default branch
- Check default branch using Git Bash
Note
Before going through this session, please visit my below-mentioned sessions related to Git and GitHub,
Learn About Git Default Branch
When we create a new repository on GitHub, there is a branch created by default as shown below,
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 see what happens after refreshing the GitHub repository as shown below,
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,
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.
Now go to these branches' details as shown below,
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
After these previous steps are completed, we can set our default branch called Development as shown below,
Now, we check branch details for checking the default branch as shown below,
Also, we can check as shown below,
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.
Using Git Bash to clone the repo as shown below,
Let's check the default branch using Git Bash.
Also, we can check the default branch or currently connected branch using a command called git branch as shown below,
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.
Describe The Uses Of These 3 Branches In Short
- Development
This branch is used for developers to commit code. After successful sanity testing in this branch, the code moved to the Satya branch.
- 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.
- 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