From your feature branch (e.g configUpdate) run:

git fetch
git rebase origin/master

Or the shorter form:

git pull --rebase

Why this works:

  • git merge branchname takes new commits from the branch branchname, and adds them to the current branch. If necessary, it automatically adds a "Merge" commit on top.

  • git rebase branchname takes new commits from the branch branchname, and inserts them "under" your changes. More precisely, it modifies the history of the current branch such that it is based on the tip of branchname, with any changes you made on top of that.

  • git pull is basically the same as git fetch; git merge origin/master.

  • git pull --rebase is basically the same as git fetch; git rebase origin/master.

So why would you want to use git pull --rebase rather than git pull? Here's a simple example:

  • You start working on a new feature.

  • By the time you're ready to push your changes, several commits have been pushed by other developers.

  • If you git pull (which uses merge), your changes will be buried by the new commits, in addition to an automatically-created merge commit.

  • If you git pull --rebase instead, git will fast forward your master to upstream's, then apply your changes on top.

Answer from Joey Adams on Stack Overflow
Top answer
1 of 1
54

Case 1: remote/master has everything that local master has

If remote/master contains all of the commits that the local master contains, simply do a git pull:

git checkout master
git pull remote master

You can check if the local master has commits that remote/master doesn't by using the following:

git fetch remote
git log --oneline --graph remote/master..master

That will show you all commits that are contained in master but not in remote/master. If you don't see any output, that means remote/master has everything that the local master has.

Case 2: local master has commits that remote/master doesn't have

If the local master contains commits that remote/master doesn't contain, you'll have to figure out how you want to handle that. Do you want to keep them and merge them with remote/master, or do you simply want to throw them away?

Case 2a: merge/rebase local master commits into remote/master

If you want to keep them, you can either merge or rebase the local master with remote/master:

git checkout master
git fetch <remote>

# Merge remote/master
git merge remote/master

# Or rebase local commits on top instead
git rebase remote/master

# Push the results
git push remote master

Case 2b: throw away local master commits

If you don't want to keep the local commits, then just do a hard reset of the local master to the same point as the remote/master:

git checkout master
git fetch remote
git reset --hard remote/master

Documentation

You can read more about all of these commands from the Git documentation. I also highly recommend the excellent free online Pro Git book, especially chapters 1-3 and 6-6.5.

🌐
Linux Hint
linuxhint.com › merge-remote-master-to-local-branch
How to Merge Remote Master to Local Branch – Linux Hint
Run the “git rebase <remote-name/remote-branch>” command. ... Next, execute the “git fetch” command to download the updated version of the desired remote repository: ... Finally, merge the remote “master” branch to the local repository branch by typing out the “git rebase” command:
🌐
Delft Stack
delftstack.com › home › howto › git › merge remote branch to local branch in git
How to Merge a Remote Branch to a Local Branch in Git | Delft Stack
February 2, 2024 - This tutorial will merge a remote git branch to a local one by cloning the remote repository and updating the changes locally.
🌐
Reddit
reddit.com › r/git › get changes from remote "parent" branch to local branch
r/git on Reddit: Get changes from remote "parent" branch to local branch
October 1, 2022 -

I'm a git rookie, so I apologize in advance if this is a stupid question.

I'm not sure if it's necessary, but I'll provide some context. I'm working on a team project. We use feature branches to implement features, which are then merged to our 'development' branch.

I created a merge request to merge my feature branch into 'development'. Then, before the feature branch was merged, I started working on a new feature branch. After working on this new feature branch I realized that I need a component from the old feature branch, which is now merged into 'development'.

How can I get the latest version of 'development' to my new feature branch? The solutions I've found online seem to suggest that I merge the branches, but that is not really an option since I don't want to touch/change the 'development' branch or anything on it.

Hopefully this makes sense.

Top answer
1 of 3
4
Generally merging can happen from any branch to any branch. If you're currently on your feature branch and your local develop branch is up to date, you can run git merge develop to merge changes from the develop branch into your feature branch. It won't make any changes to your develop branch at all. Your develop branch will remain as it is now and your feature branch will get a new commit saying something like "merge develop into feature branch" which will contain all the changes made to develop since you branched off it. An alternative is rebasing, but I wouldn't recommend it if you've already pushed your feature branch onto the remote repository. If you wanted to try it though, you can run git rebase develop (again, assuming you're on your feature branch) and it will move your feature branch to make it look like you originally branched off the latest commit in develop. This is a slightly more advanced method though and you need to be a bit more careful with it so I'd recommend the git merge method for now and perhaps do some reading around the dangers of rebase
2 of 3
1
You can rebase your new feature branch onto origin/development branch. Rebasing does basically what it says - it takes your feature, then moves it on top of a new base. In your case, your feature branch is based on an older version of development, and now you want to base it on a newer version of development. First make sure you have the latest version of the development branch: git checkout development git pull Then checkout your feature branch and rebase it! git checkout feature/ git rebase master Note: Don't do this if you've already pushed your feature branch to a remote repo. If you've done that, you're going to have to merge.
🌐
JanBask Training
janbasktraining.com › community › data-science › how-git-merge-the-remote-branch-to-local-branch
How git merge the remote branch to local branch ? | JanBask Training Community
July 14, 2021 - If you use git pull, your changes will be buried by the new commits, in addition to an automatically-created merge commit. If you use git pull --rebase instead, git will fast forward your master to upstream, then apply your changes on top.
🌐
Reddit
reddit.com › r/git › super dumb question, how to merge origin/master into my branch in one commit?
r/git on Reddit: Super dumb question, How to merge origin/master into my branch in one commit?
May 20, 2022 -

Not sure if this is the right place to ask this. My branch is behind origin master by many commits, I tried to git merge master to my branch earlier but my git log history now shows a bunch of other people’s commits, but I actually just wanted to keep my branch up-to-date with master in one commit only, something like “Merge branch ‘master’ into ‘some-branch’” any help is appreciated. Thanks

🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to merge a git branch into master
How to Merge a Git Branch into Master | phoenixNAP KB
December 17, 2025 - After switching, use the git merge command to merge another branch into master. The merge creates a merge commit that brings together multiple lines of development while preserving the history of the source branch.
Find elsewhere
Top answer
1 of 16
3750

How I would do this

git checkout master
git pull origin master
git merge test
git push origin master

If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with what I want to push and also I wouldn't push things at all, that are only for me and my local repository. In your description it seems, that test is only for you? So no reason to publish it.

git always tries to respect yours and others changes, and so will --rebase. I don't think I can explain it appropriately, so have a look at the Git book - Rebasing or git-ready: Intro into rebasing for a little description. It's a quite cool feature

2 of 16
558

This is a very practical question, but all the answers above are not practical.

Like

git checkout master
git pull origin master
git merge test
git push origin master

This approach has two issues:

  1. It's unsafe, because we don't know if there are any conflicts between test branch and master branch.

  2. It would "squeeze" all test commits into one merge commit on master; that is to say on master branch, we can't see the all change logs of test branch.

So, when we suspect there would some conflicts, we can have following git operations:

git checkout test
git pull 
git checkout master
git pull
git merge --no-ff --no-commit test

Test merge before commit, avoid a fast-forward commit by --no-ff,

If conflict is encountered, we can run git status to check details about the conflicts and try to solve

git status

Once we solve the conflicts, or if there is no conflict, we commit and push them

git commit -m 'merge test branch'
git push

But this way will lose the changes history logged in test branch, and it would make master branch to be hard for other developers to understand the history of the project.

So the best method is we have to use rebase instead of merge (suppose, when in this time, we have solved the branch conflicts).

Following is one simple sample, for advanced operations, please refer to http://git-scm.com/book/en/v2/Git-Branching-Rebasing

git checkout master
git pull
git checkout test
git pull
git rebase -i master
git checkout master
git merge test

Yep, when you have uppers done, all the Test branch's commits will be moved onto the head of Master branch. The major benefit of rebasing is that you get a linear and much cleaner project history.

The only thing you need to avoid is: never use rebase on public branch, like master branch.

Never do operations like the following:

git checkout master
git rebase -i test

Details for https://www.atlassian.com/git/tutorials/merging-vs-rebasing/the-golden-rule-of-rebasing

appendix:

  • if you are not sure about rebasing operations, please refer to: https://git-scm.com/book/en/v2/Git-Branching-Rebasing
Top answer
1 of 5
536

You can reference those remote tracking branches ~(listed with git branch -r) with the name of their remote.

You need to fetch the remote branch:

git fetch origin aRemoteBranch

If you want to merge one of those remote branches on your local branch:

git checkout aLocalBranch
git merge origin/aRemoteBranch

Note 1: For a large repo with a long history, you will want to add the --depth=1 option when you use git fetch.

Note 2: These commands also work with other remote repos so you can setup an origin and an upstream if you are working on a fork.

Note 3: user3265569 suggests the following alias in the comments:

From aLocalBranch, run git combine remoteBranch
Alias:

combine = !git fetch origin ${1} && git merge origin/${1}

Opposite scenario: If you want to merge one of your local branch on a remote branch (as opposed to a remote branch to a local one, as shown above), you need to create a new local branch on top of said remote branch first:

git checkout -b myBranch origin/aBranch
git merge anotherLocalBranch

The idea here, is to merge "one of your local branch" (here anotherLocalBranch) to a remote branch (origin/aBranch).
For that, you create first "myBranch" as representing that remote branch: that is the git checkout -b myBranch origin/aBranch part.
And then you can merge anotherLocalBranch to it (to myBranch).

2 of 5
120

Whenever I do a merge, I get into the branch I want to merge into (e.g. "git checkout branch-i-am-working-in") and then do the following:

git merge origin/branch-i-want-to-merge-from

🌐
GitHub
gist.github.com › sinewalker › 3b07efab5791bf39c05b27f103b2d391
Merge remote origin/master into a new local repository · GitHub
Use commands like these to merge in a remote to your local master, as the new origin: git remote add origin git@github.com:user/repo git fetch origin git checkout origin/master git checkout -b temp git checkout -B master temp git branch -d temp git branch --set-upstream-to=origin/master master
🌐
Togaware
togaware.com › linux › survivor › Git_Merge_Master_into.html
Git Merge Master into Branch
Notice that we could skip the first two lines and change the merge to merge origin/main to also effect a merge from the remote main into the current branch. This will not then update the local copy of main.
🌐
Varonis
varonis.com › blog › how-to-merge-in-git
How to Merge in Git: Remote and Local Git Repositories Tutorial
April 6, 2023 - Next, I want to pull down the contents ... the git pull command and specifying the origin remote repository and the local main branch: ... Since we have two unrelated projects with different histories, Git is refusing to merge the two....
🌐
Atlassian Community
community.atlassian.com › q&a › bitbucket › questions › confused about the local master and the remote master
Confused about the Local Master and the Remote Master
July 19, 2017 - The main difference between a local branch and a remote branch is where it's located: local is kept on your own system, and remote is kept someplace else (such as Bitbucket). A `git push` or `git pull` can help you synchronize the two, but otherwise they're independent of each other. If you push a feature branch to a remote, then the commits are not on any master until you merge them.
🌐
GitHub
gist.github.com › solrevdev › 47de1c65ca4ef62a47b6ae9ce8d586a4
Updating local master from remote then merge those new changes to a feature branch · GitHub
Merge the changes from origin/master into your local master branch. This brings your master branch in sync with the remote repository, without losing your local changes. If your local branch didn't have any unique commits, Git will instead perform ...
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › git merge master into branch
Git Merge Master into Branch {Two Methods Explained}
October 2, 2023 - The sections below show different methods for merging the master branch into another branch. Use git rebase when you are working only in the local repository, or when working with a remote repository that is not publicly visible.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-a-git-branch-into-master
How to Merge a Git Branch into Master? - GeeksforGeeks
May 22, 2024 - Fetch and integrate the latest changes from the remote repository. ... Switch to the branch you want to merge into master. ... Update your feature branch with the latest changes from master to minimize conflicts. ... Move back to the master branch to prepare for the merge. ... Merge the changes from your feature branch into master. ... If Git reports conflicts, you'll need to resolve them manually.
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git merge
Git Merge | Atlassian Git Tutorial
Once the previously discussed "preparing to merge" steps have been taken a merge can be initiated by executing git merge <branch name> where <branch name> is the name of the branch that will be merged into the receiving branch.
🌐
Git Tower
git-tower.com › learn › git faq › how to merge branches in git with git merge
How to Merge Branches in Git with git merge | Learn Version Control with Git
5 days ago - The [behind 1] remark tells us that "master" has received new changes on the remote. We must update "master" before we can integrate our own changes. If properly configured, a plain "git pull" should suffice (after making "master" our active branch): ... The last thing to check before actually starting the merge process is our current HEAD branch: we need to make sure that we've checked out the branch that should receive the changes.