git checkout custom_branch && git rebase master

This will update custom_branch with changes from master branch.

Don't forget to make sure master is up to date first. git pull


This is also possible with git checkout custom_branch && git merge master


For an explanation on why the first one is (probably) what you should be using: When do you use git rebase instead of git merge?

Answer from tehp on Stack Overflow
🌐
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

Discussions

what does git merge origin/master do? - Stack Overflow
You may find git help rev-parse ... how git attempts to resolve ref names or other notations into commits. ... Sign up to request clarification or add additional context in comments. ... What this does is merges the branch referred to as origin/master into your current branch. The order is very important. The word origin means the place from which you ... More on stackoverflow.com
🌐 stackoverflow.com
Difference between git merge master and origin/master? - Stack Overflow
I am trying to merge master branch into my current branch because my current branch does not have few commits which are present in master branch. ... Have you tried git pull origin master in your local master branch and try to run the above commands again, and see if there is a difference ? ... @RabeeAbdelWahab, I thought git fetch origin command will update local master branch with changes from ... More on stackoverflow.com
🌐 stackoverflow.com
git - How to merge remote master to local branch - Stack Overflow
If you git pull (which uses merge), ... merge commit. If you git pull --rebase instead, git will fast forward your master to upstream's, then apply your changes on top. ... Sign up to request clarification or add additional context in comments. ... I did this on the correct branch but I can still see differences between my local files and the remote master branch of the original project (even ... More on stackoverflow.com
🌐 stackoverflow.com
merge - merging (git) origin to my current local working branch - Stack Overflow
I believe if I do git fetch origin/git ... master only. If I do git fetch origin/git merge origin/newbranch, that wont work, I get message like 'merge: origin/newbranch- not something we can merge'. ... Save this answer. ... Show activity on this post. newbranch should be current branch, to make sure you can checkout it, then you get updated from you repo using ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-origin-master
Git Origin Master - GeeksforGeeks
March 14, 2026 - git push origin master sends local commits to the remote master branch. git pull origin master fetches and merges updates from the remote master branch into the local repository.
Top answer
1 of 2
28

git merge origin/master can do one of two things (or error).

In the first case, it creates a new commit that has two parents: the current HEAD, and the commit pointed to by the ref origin/master (unless you're doing something funny, this is likely to be (the local pointer to) the branch named master on a remote named origin, though this is completely conventional).

In the second case, where there is no tree-level merge necessary, rather than creating a new commit, it updates the currently checked-out ref to point to the same commit as is pointed to by origin/master. (This is called a fast-forward merge -- git can be directed to either always or never do this when you merge through command-line flags).

It does not call git commit directly, which is a higher-level (porcelain in the git-parlance) command intended for users.

Calling git merge master/original will try and resolve master/original to a commit, which will almost certainly (again, unless you've done something deliberate) not be the same as origin/master. If you happen to have a remote named master that has a branch named original, it will create a new commit which has that as the second parent.

You may find git help rev-parse to be helpful in deciphering how git attempts to resolve ref names or other notations into commits.

2 of 2
12

What this does is merges the branch referred to as origin/master into your current branch. The order is very important. The word origin means the place from which you cloned your repository, i.e., the origin of the repository, the word master is just a branch name, however master is usually used as the main branch, or the trunk branch as some other systems call it.

Merge might need to do a commit depending on the state of your development. If your history hasn't diverged from the origin, it can do what is called a fast-forward---all that needs to be done is put the new history on top of yours. If your development has diverged from the origin then if the merge can be done with no conflicts then the merge is done and a new commit is recorded at HEAD to specify the merge and the two parents.

Furthermore, if merging can't be done because of a conflict, your working copy is updated to reflect the fact that there are conflicts, then when you fix them, you manually make the commit that records the merge.

🌐
Togaware
togaware.com › linux › survivor › Git_Merge_Master_into.html
Git Merge Master into Branch
Then checkout the branch of interest and merge from the updated local main. We can then push the merges back to the remote repository's version of the branch. The commits are those that were committed by others to the remote repository's main 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.
Find elsewhere
🌐
JanBask Training
janbasktraining.com › community › devops › merging-changes-from-master-into-my-branch
Merging changes from master into my branch | JanBask Training Community
June 2, 2025 - Alternative: Using git pull on master before merging · Some developers prefer to first update their local master branch: git checkout master git pull origin master git checkout your-branch-name git merge master
🌐
GitHub
gist.github.com › sinewalker › 3b07efab5791bf39c05b27f103b2d391
Merge remote origin/master into a new local repository · GitHub
Use commands like these to merge ... git checkout -b temp git checkout -B master temp git branch -d temp git branch --set-upstream-to=origin/master master...
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › git merge master into branch
Git Merge Master into Branch {Two Methods Explained}
October 2, 2023 - This tutorial shows two methods for merging the master branch into a different one in Git. See examples and use case scenarios.
🌐
Graphite
graphite.com › guides › git-merge-main-into-another-branch
Git merge main branch into another branch - Graphite
This command brings in the changes from origin/main to your current branch (feature-branch). Conflicts may arise during the merge if the changes in the main branch are in conflict with the changes in your feature branch.
🌐
W3Schools
w3schools.com › GIT › git_branch_merge.asp
Git Branch Merge
To combine the changes from one branch into another, use git merge. Usually, you first switch to the branch you want to merge into (often main or master), then run the merge command with the branch name you want to combine in.
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
🌐
Delft Stack
delftstack.com › home › howto › git › git merge origin master
Difference Between Git Merge Master and Git Merge Origin/Master | Delft Stack
March 11, 2025 - Therefore, if you have made changes to the master branch locally, those changes will be merged into your current branch. On the other hand, the command git merge origin/master merges changes from the remote master branch into your current branch.
🌐
Git Scripts
gitscripts.com › git-merge-origin-master-into-branch
Git Merge Origin Master Into Branch: A Quick Guide
May 8, 2025 - To merge effectively, you should first fetch the latest changes from the remote repository. The command `git fetch` updates your local copy of the repository, providing you with information about new commits on the remote branches. ... This command prepares you to merge the latest changes from `origin master` into your branch.
🌐
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.
🌐
GitHub
gist.github.com › santisbon › a1a60db1fb8eecd1beeacd986ae5d3ca
Deploying from Git branches adds flexibility. Bring your feature branch up to date with master and deploy it to make sure everything works. If everything looks good the branch can be merged. Otherwise, you can deploy your master branch to return production to its stable state. · GitHub
@deepika0024-tech I believe you perform the same process as mentioned in the first post, but you might come across some conflicts like msureshb. ... git checkout <feature-branch> git fetch -p origin git merge origin/master git push origin ...
🌐
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 - This step-by-step guide shows how to merge a Git branch into the master (or main) branch using the git merge command.