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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay