DEV Community

Gurmeet Singh
Gurmeet Singh

Posted on

git merge vs git pull

Over the years I have seen developers use two approaches to add code from one branch to another. For example, suppose you have two branches: "main" and "new-feature". You have been working on "new-feature" for a while and now you want to merge the changes you made into "main". To do this, developers generally use one of two ways:

  1. Checkout the main branch and run git merge new-feature
  2. Checkout the main branch and run git pull origin new-feature (This is the approach which is generally used when we create pull requests from the UI of various git hosting platforms (e.g. GitHub, GitLab, Bitbucket))

And I asked many people about this but no one seems to know the exact difference and they had just picked up one approach and been using it forever.


Here's the difference -

git merge is used to merge a branch into the current branch, while git pull is used to fetch and merge changes from a remote repository into the current branch. In other words, git pull is a combination of git fetch and git merge. git fetch retrieves new commits from a remote repository, but does not merge them into the current branch. git merge is then used to integrate the changes from the remote branch into the local branch.

Top comments (0)