Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: merge remote changes

Tags:

git

Let's say, I have a branch with my own changes and one commit. But the remote branch is a few commits ahead as well. What is the best way to merge in the remote changes locally, not to generate merge commits?

like image 285
Liglo App Avatar asked Jun 14 '26 22:06

Liglo App


2 Answers

You can use a rebase (git rebase):

git checkout branch
git fetch origin
git rebase origin/branch

You will replay your commits on top of the updated remote tracking branch origin/branch (replace branch by the actual name of the branch)

Even shorter:

git pull --rebase origin branch

That is valid since you haven't yet pushed 'branch', and will allow you to resolve any merge issue locally.

like image 130
VonC Avatar answered Jun 16 '26 12:06

VonC


You can do a simple merge, or you can rebase your changes on the remote branch

L1: local commit

B-C-D Remote commits

A--L1
 \
  B--C--D

A--B--C--D--L1

do a simple fetch and then rebase.

like image 39
Michael Mairegger Avatar answered Jun 16 '26 14:06

Michael Mairegger