Git

How to Git Merge | Beginner Git Tutorial

Git users can connect the forked history (history related to copying repositories) through the merging procedure. This method combines multiple developing histories. More specifically, the “$ git merge” command can be used for this specified purpose. It enables developers to fetch the data created by the Git branch and merge them into one branch.

This post will discuss the method to merge local branches.

How to Git Merge?

To merge Git branches, firstly, navigate to the repository, and create a file. Next, track a new file in the repository and update the repository by committing changes. Then, execute the “$ git merge <branch>” command to merge the Git local branches. Lastly, check the branch log history.

Now, let’s move ahead to implement the provided scenario!

Step 1: Navigate to Repository

First, move to the Git desired local repository using the “cd” command:

$ cd "C:\Users\nazma\Git\Alpha"

Step 2: Create File

Next, execute the “touch” command to create a new file in the repository:

$ touch file1.txt

Step 3: Track File

Run the “git add” command to track the file from the working directory to the staging area:

$ git add file1.txt

Step 4: Update Repository

Next, save the added changes to the repository by utilizing the “git commit” changes with the required message:

$ git commit -m "file1.txt added"

Step 5: Create and Switch Branch

Now, create and switch branch with the help of the provided command:

$ git checkout -b alpha

Step 6: Merge Master Branch

Execute the “git merge” command with the branch name. In our case, we have added “master” as the branch name:

$ git merge master

Step 7: Check Branch Log History

Lastly, run the “git log” command to check the branch log history:

$ git log .

That’s it! We have offered the procedure to merge branches.

Conclusion

To merge branches, firstly, move to the directory and create a new file. Then, track a new file in the repository and commit changes. After that, run the “$ git merge <branch>” command to merge the Git local branches. Lastly, check the branch log history. In this post, we have described the method to utilize the git merge command for merging branches.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.