Git

How to Merge Remote Master to Local Branch

Git is the most popular tracking software with different features that make a user’s life more efficient. The best thing about Git is that developers can easily generate new and merge GitHub remote branches with the local repository branches. The β€œgit rebase <remote-name/branch>” command can be used for the previously described purposes.

This post will discuss the method of merging a GitHub branch with the Git local branch.

How to Merge GitHub Master Branch to Local Branch?

To merge the GitHub master branch to the Git local branch, try the following instructions:

    • Go to the Git root directory.
    • List all the branches.
    • Check the remote URL list.
    • Download the remote repository into the local machine.
    • Verify it by checking the branches list.
    • Run the β€œgit rebase <remote-name/remote-branch>” command.

Step 1: Switch to Root Directory

First, move to the root directory by typing out the β€œcd” command:

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

 
Step 2: List All Branches

Then, use the β€œgit branch” command to display the local as well as remote branches:

$ git branch -a

 
According to the provided output, the root directory has no remote branch:


Step 3: Check Remote URL

Next, check the remote URL by running the β€œgit remote” command:

$ git remote -v

 

Step 4: Make Copy of Remote Branches

Next, execute the β€œgit fetch” command to download the updated version of the desired remote repository:

$ git fetch

 
It can be seen that all remote branches are fetched successfully in the local repository:


Step 5: Verify Fetched Branches

After that, to ensure all remote branches are fetched or not, utilized the provided command:

$ git branch -a

 
As you can see, remote branches are downloaded successfully:


Step 6: Merge Remote Master

Finally, merge the remote β€œmaster” branch to the local repository branch by typing out the β€œgit rebase” command:

$ git rebase origin/master

 
According to the following output, the current working branch, β€œmaster” is up-to-date which indicates that it is previously merged with the local repository branch:


You have learned the easiest way of merging the GitHub master branch to the Git local branch.

Conclusion

To merge the GitHub master branch to the Git local branch, first, go to the Git root directory. Then, list all the branches and check the remote URL list. Next, download the remote repository into the local machine and verify it by checking the branches list. After that, execute the β€œgit rebase <remote-name/remote-branch>” command. This post demonstrated the process of merging a GitHub branch to a Git local branch.

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.