Create Git Branch, Modify Branch and Merge to Main Branch Step by Step - 9

 We have a project. Here as a sample, the project is just an Employees.txt file. Which is already initialized with the git. Here we will create a new branch and add a feature to that. Once we feel that the feature is good then we will merge the new branch with the main/master branch.

Project current data - 
Project File
The initial status of data

Step by step we will create a new branch. We will modify in new branch and finally, we merge the new branch with the master branch with the changes.

Step 1:  Create a new branch.

Create a branch. Here serial-version is the name of the new branch.
 git branch serial-version

See all branches
 git branch 
 
Create branch
Here first we have checked the branches before creating our new branch. It shows only the master branch is available. Then we created a new branch(serial-version branch) and checked again it's created.

Step 2: Checkout/move to new branch.
Currently, we are in the master branch. So we will move from the master branch to the serial-version branch.

See all the branches. And then chose one to move.
 git branch
 
Move to serial-version branch.
 git checkout serial-version
 
Screenshot of new branch checkout
Successfully Moved 

 
A short way to create and checkout to a new branch with a single command.
 git checkout -b table-version-new

Step 3: Modify/Add a feature on a new branch.

Now we are in the serial-version branch and will modify our project. Then add, and commit to the new branch.
Project modified
Add the changes in serial-version branch.
git add --all 

Commit change to serial-version branch.
git commit -m "Serial number added"
New changes commit
New changes are committed to new 'serial-version' branch.


Step 4: Merge the new branch with the main/master branch.
It's very simple to merge a branch with the main/master branch. First need to checkout in master branch.

Checkout in the master/main branch and check the all branch
 git checkout master 
 git branch 
Back to master branch


Here two branches are available.
  • Master Branch
  • Serial-version Branch
 And we are in the master branch. This master branch has the earlier version of the project(Without serial numbers). Now we will merge the serial-version branch with the master branch.

Merge the serial-version branch with the master branch
 git merge serial-version  

See the log of the merge
 git log --oneline
Merge new branch with master branch


All processes are done. Now the changes from the new branch have been added to the Master branch successfully...😀

Post a Comment

0 Comments