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
🌐
Uidaholib
uidaholib.github.io › digital-collections-docs › content › maintainers › merging.html
Merging Main into Branch | Digital Collections Docs
First, always make sure your main branch is up-to-date, switch to main and do a git pull. In GitHub Desktop (or VS Code), find the branch you want to update and switch to it. Do a fetch and git pull to update this branch with any remote changes.
Discussions

How to Merge Master into a Feature Branch
I wouldn't. I usually just rebase feature branches onto master when they diverted too much. Unless this branch is collaborative, it should pose no issues. Just do so locally: [assuming you're on the feature branch and the remote is called origin] git fetch git rebase origin/master git push --force-with-lease More on reddit.com
🌐 r/git
14
2
March 13, 2024
Is it wrong to merge master into a branch i.e. ideally should you use rebase instead?
Nothing wrong at all with merging master into another branch so long as you know what you are doing and this is what you want. More on reddit.com
🌐 r/git
36
6
February 23, 2021
What does it mean to merge master into feature branch?

You’re being asked to make sure that your feature branch is up to date with master. New changes may have been made since you created the branch, and you might run into a nasty merge if you don’t integrate them into your branch beforehand.

You can do something like git pull origin master while checked out on your branch to do this.

More on reddit.com
🌐 r/git
29
1
October 1, 2020
Merging your branch into main after many other branches have been merged into it
Sometimes merge conflicts are unavoidable, and that's ok, because Git is – relatively – good at dealing with them. However, if the number of conflicts becomes abnormally large to deal with, this reeks more of an organisational problem: merge conflicts only occur when the two branches touch the same line(s) of code. If apparently all of you 5 devs had to work on the same lines/functions, then your code should probably be restructured, and your boss should divide work in such a way that each of you can work (mostly!) independent of each other. Sometimes big changes across the whole codebase are unavoidable, but they should not be the norm. Should I always keep my branch up-to-date whenever someone merges their changes into main? I know the thought is tempting, and resolving small conflicts certainly is easier, but you'll have to be careful to not waste a big part of your time by resolving conflicts over and over again, when you could be writing code instead. More on reddit.com
🌐 r/git
8
2
August 22, 2023
People also ask

What is creating a branch in Git?
Creating a branch takes a snapshot of the existing code so you can work on it independently of the main branch.
🌐
varonis.com
varonis.com › blog › git-branching-and-merging
Git Branching and Merging: A Step-By-Step Guide
What's the difference between `git merge` and `git rebase`?
Both `git merge` and `git rebase` integrate changes from one branch into another, but they do it differently: * `git merge` creates a new merge commit, preserving the entire history of both branches. * `git rebase` rewrites the commit history by creating new commits for each commit in the original branch and applying them to the main branch. This results in a linear history.
🌐
blog.openreplay.com
blog.openreplay.com › openreplay blog › how to git merge main into branch: a step-by-step guide
How to Git Merge Main into Branch: A Step-by-Step Guide
How do I create a new branch in Git?
Use the git branch command and specify the branch name, e.g., git branch feature1.
🌐
varonis.com
varonis.com › blog › git-branching-and-merging
Git Branching and Merging: A Step-By-Step Guide
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
🌐
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.
🌐
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:
🌐
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.
Find elsewhere
🌐
Graphite
graphite.com › guides › how-to-merge-branch-to-main-in-git
How to merge a Git branch into main - Graphite
We'll cover how to merge from both feature branches into main and how to update a feature branch with the latest changes from main. A merge in Git creates a single commit that brings together the histories of both branches, ideally maintaining the history of both and creating a new point where the combined work continues.
🌐
OpenReplay
blog.openreplay.com › openreplay blog › how to git merge main into branch: a step-by-step guide
How to Git Merge Main into Branch: A Step-by-Step Guide
December 19, 2024 - Merging main into your branch integrates the latest changes from the main development line. Always ensure your branch is up to date before merging. Resolve any merge conflicts carefully, keeping the desired changes.
🌐
Varonis
varonis.com › blog › git-branching-and-merging
Git Branching and Merging: A Step-By-Step Guide
September 12, 2025 - This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
🌐
codemaga
codemaga.com › git › git-merging-main-into-branch
Git Merging main into Branch: Best Practices - codemaga
April 27, 2024 - It’s recommended to use git rebase only in the local repository or on solo projects. ... Maintain Clean History: Choose the method (merge or rebase) based on your project’s needs and desired commit history. Resolve Conflicts: Be prepared to resolve merge conflicts, especially when integrating divergent changes. Collaborative Workflow: Communicate with your team to coordinate main merges and ensure alignment across branches. Regular Merging: Merge main into feature branches periodically to stay updated with the latest changes.
🌐
Reddit
reddit.com › r/git › how to merge master into a feature branch
r/git on Reddit: How to Merge Master into a Feature Branch
March 13, 2024 -

I need advice on how to merge master into a feature branch.

I began working on a new feature last year, and then was pulled away to other things. Master had substantially changed, so I wanted to merge it back into the feature branch, because I can't keep working on the feature until those changes are incorporated into that branch.

I tried this in Github, but I could only merge into master, even when I selected merge into the feature branch. I finally just merged into master and manually updated the changes on the feature branch (which had been overwritten) through cut-and-paste on the feature branch. But this seems like a common task, and I don't want to have to do that again if I can help it.

Thanks in advance for any help; I did consult the Git book, but I couldn't find anything specific about this task.

🌐
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.
🌐
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.
🌐
Mergify
mergify.com › blog › git-merge-main-into-branch
How to merge main into a branch in Git (and when to rebase instead) | Mergify
They produce different histories, and the choice has consequences for the people who read your PR and the people who run git log six months from now. git merge origin/main keeps your branch’s history intact and adds a merge commit at the tip ...
🌐
Namehero
namehero.com › blog › how-to-merge-a-git-branch-to-master
How to Merge a Git Branch to Master
October 6, 2025 - To do this, you create a separate branch that we will call “feature-branch” in future code examples. All development on this new feature happens in feature-branch. When the time comes, we “merge” the changes you made in feature-branch into the main branch.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-a-git-branch-into-master
How to Merge a Git Branch into Master? - GeeksforGeeks
May 22, 2024 - Merge the changes from your feature branch into master. ... If Git reports conflicts, you'll need to resolve them manually.
Top answer
1 of 1
144

You can either git merge master or git rebase master.

If the branch has not been distributed to other people, in this case i would prefer git rebase.

Because git rebase makes it as if the changes on the feature branch were made on top of the changes on the master branch, which makes the version graph simpler.

Rebase

Taking the example from the git rebase manual, git rebase master in branch feature:

      A---B---C feature                             A'--B'--C' feature
     /                   --rebase-->               /
D---E---F---G master                  D---E---F---G master

However, git rebase is only suitable when nobody else is working on it, or there will be confusion and extra work for them, because the old commits A, B, C are now replaced by new commits A', B', C', plus F and G that were not there before.

The actual result after git rebase master in branch feature is this:

      ( A---B---C ) feature@{1}
       /
      /       A'--B'--C' feature
     /       /
D---E---F---G master

Commits A, B, C are dangling after the rebase, but are reachable through git reflog feature as feature@{1}.

Merge

If someone has pulled your branch, or you have pushed it somewhere, you should merge into it instead, to avoid confusion and extra work on the other end. See Recovering from upstream rebase.

This is the result of git merge master in branch feature:

      A---B---C feature                    A---B---C---M feature
     /                   --merge-->       /       ,---’
D---E---F---G master                 D---E---F---G master

Alternatively, if you git merge feature in branch master, it would look like this:

      A---B---C feature                    A---B---C feature
     /                   --merge-->       /         \
D---E---F---G master                 D---E---F---G---M master
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › how do you merge a git branch?
How do you merge a Git branch? | Solutions to Git Problems
February 7, 2025 - You will then merge changes from the feature branch over to main, adding all changes from the feature branch to main. This gives you an accurate representation of the history, in addition to getting all the changes combined onto main. To make the process even easier, you can use a Git client, like GitKraken, to visualize the branching process in Git.
🌐
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.
🌐
Stack Abuse
stackabuse.com › git-merge-branch-into-master
Git: Merge Branch into Master
April 20, 2023 - Note: git merge merges the specified branch into the currently active branch. So we need to be on the branch that we are merging into. If you're merging a new feature into the main branch, you first want to switch to the main branch and then merge into it: