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 -
The initial status of data |
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
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.git branch
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.
A short way to create and checkout to a new branch with a single command.
git checkout serial-version
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.
Add the changes in serial-version branch.
git add --all
Commit change to serial-version branch.
git commit -m "Serial number added"
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 mastergit 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
All processes are done. Now the changes from the new branch have been added to the Master branch successfully...😀
0 Comments