Merge a branch to main
Merging a branch into the main branch is essential to bring your developed features, bug fixes, or experiments into the production-ready codebase. By merging, you consolidate your changes and incorporate them into the main branch, making them accessible for the entire project. This ensures that your work becomes a part of the stable and maintained code.
In this part of our tutorial, we will guide you through the process of merging a branch, ensuring a seamless integration of your work into the main branch.
Let’s merge the branch you just created (i.e., issue1
) along with its commit to main
.
To merge our commits into the main branch, we must first switch to the main branch.
$ git checkout main
Switched to branch 'main'
Before merging, open the myfile.txt
file and check the content of the file. You’ll see this:
Anyone can learn Git with this tutorial and Backlog
As you’ll see, the change added on issue1
we made in the previous step isn’t included in the myfile.txt
file on the main branch.
When you use the git merge command, the specified commit will merge with the active branch. Using the following command, we can now merge.
$ git merge issue1
Updating 1257027..b2b23c4
Fast-forward
myfile.txt | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
The position of the main branch will now move over to that of issue1
, executing a fast-forward merge.
Finally, let’s confirm the content of the myfile.txt
file. Open myfile.txt
, and you will see the new line we committed to the issue1
branch is now on the main branch.
Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index