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

git - Can I split a feature branch and then merge it back to the origin master branch without any issues? - Software Engineering Stack Exchange
I'm working on a project where the master branch is protected. Usual workflow: Always create feature branches off master and then send PRs. Once that has been merged into origin/master, I can pull it More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
November 18, 2022
How do I merge a new branch into my main branch? I am running into issues
I created a new branch called aws. I am trying to merge it into master (which is my main branch) I have tried to do git checkout master git merge aws It tells me it's "Already up to date" I then tried git checkout master git reset --hard master I keep reading suggestions and I am not making ... More on community.atlassian.com
🌐 community.atlassian.com
October 5, 2022
git - How to merge remote master to local branch - Stack Overflow
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. More on stackoverflow.com
🌐 stackoverflow.com
version control - Get changes from master into branch in Git - Stack Overflow
Ie. git rebase otherbranch? It seems I was a little off in my question, I branched from a branch then made changes to the original branch. 2011-03-17T15:39:14.333Z+00:00 ... If im right, rebase on the pull request it will show all the master commits. if you use merge/origin master all master ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Graphite
graphite.com › guides › git-merge-main-into-another-branch
Git merge main branch into another branch
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. Here’s how to handle them: Identify the files with conflicts: Git will list conflicts during the merge.
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
All you have to do is check out the branch you wish to merge into and then run the git merge command: $ git checkout master Switched to branch 'master' $ git merge iss53 Merge made by the 'recursive' strategy.
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-origin-master
Git Origin Master - GeeksforGeeks
March 14, 2026 - git pull origin master fetches and merges updates from the remote master branch into the local repository.
Find elsewhere
🌐
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.
🌐
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
Top answer
1 of 2
1

You can certainly branch off of any branch. If your refactor branch is long-lived, and you need to add a new feature based off it the work you've already done, create feature2 off the refactor branch.

However, those 2 branches are intertwined now. You'll need to regularly pull from refactor into feature2 (in addition to pulling from main into refactor). Your PR from feature2 into refactor will only reflect the diffs between those 2 branches, but when you open a PR from refactor into main you will get see diffs from feature2 as well - something to keep in mind for whoever is reviewing.

In order for the feature2 PR to be as clean as possible, the changes you make in feature2 should be completely unrelated to the changes you're making in refactor. When you start changing the same functions in the same files on the two branches, that means conflicts. Given your use-case though (the feature depends on the work you're doing in the refactoring) this may be unavoidable.

Given all that, I'd caution about having such a long-lived branch (refactor) that you are doing other development on (feature2) at the same time. If this is truly a refactoring, adding in new features can complicate the determination that the refactoring was successful (is a bug due to the refactor or the new feature). So while it is possible to branch off of your refactoring branch, I'd evaluate whether you really want to do that, or focus on wrapping up the refactoring first.

2 of 2
1

Use git rebase to move the branches (refactor and feature) when work happens on the other branches (main and refactor) and finally when refactoring is merged. You can also move the commits from refactor that you need in feature to the base and first merge those into main rebasing refactor and feature on the merge of those changes.

Given new changes in refactor do:

git switch feature;
git rebase refactor...feature --onto refactor

Graphically you are doing. From:

*    Refactor: new changes feature should be rebased on these
| *  Feature
| *  a commit in Feature
|/
*    Fearure...Refactor (common base of Feature and Refactor)
*    a commit in Refactor
*    Main: before starting refactorring

To:

*    Feature
*    a commit in feature
*    Refactor: new changes feature should be rebased on these
*    this was the common base now it's just a commit
*    a commit in Refactor
*    Main: before starting refactoring

For changes in Main you rebase in two steps first Refactor onto Main then Feature onto the moved Refactor. Make sure to remember the hash of the base of feature (on create a tempoeary branch for it):

git branch tmp/feature-base feature...refactor;
git switch refactor;
git rebase refactor...main --onto main;
git switch feature;
git rebase tmp/feature-base --onto refactor;
git branch -D tmp/feature-base;

Graphically from:

*   Main: new changes both branches should have these
| * Feature
| * a commit in Feature
| * tmp/feature-base, Refactor
| * a commit in Refactor
|/
*   Refactor...Main: before starting refactoring

Intermediate:

*   Refactor
*   a commit in refactor
*   Main: new changes both branches should have these
| * Feature
| * a commit in Feature
| * tmp/feature-base: this commit is no longer is the refactor branch but it is in the history of Feature
| * a commit in Refactor
|/
*   before starting refactoring

To:

*   Feature
*   a commit in Feature
*   Refactor
*   a commit in refactor
*   Main: new changes both branches should have these
*   before starting refactoring

Once Refactor is merged into main rebase Feature onto the merge commit, this leads to a semi linear history with features visible and small commits that tell a story about why the code is as.

*   Feature
*   a commit on feature
*   merge refactor into main
|\
| * Refactor
| * a commit in refactor
|/
*   before starting refactoring

Don't be affraid of rebasing or merge conflicts.

🌐
Uidaholib
uidaholib.github.io › digital-collections-docs › content › maintainers › merging.html
Merging Main into Branch | Digital Collections Docs
In the Branches dropdown on GitHub Desktop, click the bottom button that says “Choose a branch to merge into [whatever branch you’re on],” and choose the “main” branch.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-get-changes-from-master-into-a-branch-in-git
How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks
April 22, 2025 - In Git, branches are essential for organizing and managing development work. Whether you are working on a feature, a bug fix, or any other task, you often work in a separate branch so that the changes don’t directly affect the master or main branch (the primary production branch). ... Merging allows you to integrate changes from one branch (e.g., master) into another branch (e.g., your feature branch).
🌐
Atlassian Community
community.atlassian.com › q&a › bitbucket › questions › how do i merge a new branch into my main branch? i am running into issues
How do I merge a new branch into my main branch? I am running into issues
October 5, 2022 - Could you please diff the branches to confirm the output? You can run the following command to do that: ... If there's no output, that means you simply need to check out aws again, commit the changes you made and confirm that running git diff master..aws actually yields a result. Then you can checkout master and merge.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-merge-master-into-any-branch-in-GitLab
How to merge master into any branch in GitLab by examples
A developer can use the following commands to merge master into any branch in GitLab: git checkout fun_feature git merge master ls git reflog git push origin fun_feature
🌐
GitHub
gist.github.com › sinewalker › 3b07efab5791bf39c05b27f103b2d391
Merge remote origin/master into a new local repository · GitHub
Use commands like these to merge ... origin/master git checkout -b temp git checkout -B master temp git branch -d temp git branch --set-upstream-to=origin/master master...
🌐
Quora
quora.com › How-do-I-merge-a-branch-with-the-master-in-Git
How to merge a branch with the master in Git - Quora
Answer (1 of 3): Assuming you don’t know which branch you’re on currently, you’ll want to: 1. Double-check that you don’t have any uncommitted work: [code ]git status[/code] 2. Commit anything still uncommitted: [code ]git add -A && git commit[/code] 3. Check out the master branch: ...
🌐
Varonis
varonis.com › blog › git-branching-and-merging
Git Branching and Merging: A Step-By-Step Guide
September 12, 2025 - Yes, use the git push command to set the upstream branch, e.g., git push –set-upstream origin <branch name>. Switch to the main branch using the git checkout command, then merge the branch using the git merge command along with the branch name.
🌐
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 - The command switches to the master branch. After switching, use the git merge command to merge another branch into master.