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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay