Git

How to Combine Local Repository Changes Using “git merge” Command in Git?

Git is the most widely utilized tool to manage source code files. It can be used to manipulate and handle all types of projects. In Git, merging is used to combine changes from different branches or repositories into a single branch. When users collaborate with numerous programmers on the same initiative, every programmer may simultaneously make changes to the same files.

This guide will briefly discuss the process of combining local repository changes using the “git merge” command in Git.

How to Combine Local Repository Changes Using “git merge” Command in Git?

To combine the local repository changes using the “git merge” command in Git, do follow the below-stated step-by-step procedure:

  • Go to the local Git repository.
  • Execute the “ls” command for listing existing content.
  • List all branches using the “git branch” command.
  • Utilize the “git checkout” command, set the branch name, and switch to it.
  • Combine local repositories using the “git merge” command.

Step 1: Go to Local Git Repository
First, set the Git local repository path with the help of the “cd” command and navigate to it:

cd "C:\Users\user\Git\demo1"

Step 2: List Content
Execute the “ls” command to list the available content:

ls

As a result, the content has been listed successfully:

Step 3: List All Branches
To list the branches, execute the “git branch” command:

git branch

The below-stated output indicates that there are only two branches:

Step 4: Switch to the Target Branch
Next, switch to the target branch by utilizing the “git checkout” command along with the branch name:

git checkout feature

It can be observed that we have successfully switched to the target branch:

Step 5: Combine Local Repository
Run the “git merge” command and add the branch name with whom you want to combine:

git merge master

It can be noticed that the local branch “master” changes has been merged inside the “feature” branch:

Step 6: View Git Log
Lastly, check out the Git log by executing the “git log –oneline” to show each commit in a single line:

git log --oneline

According to the provided output, the local repository changes have been combined successfully:

That’s all about combining the local repository changes using the “git merge” command in Git.

Conclusion

To combine/merge the local changes using the “git merge” command in Git, first, go to the Git local repository. Next, list the available content by executing the “ls” command. Then, make a list of branches and switch the target branch. After that, merge local repositories by running the “git merge” command. This guide demonstrated the way to combine local repository changes using the “git merge” command.

About the author

Hafsa Javed