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
🌐
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.
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
🌐
Reddit
reddit.com › r/git › is it wrong to merge master into a branch i.e. ideally should you use rebase instead?
r/git on Reddit: Is it wrong to merge master into a branch i.e. ideally should you use rebase instead?
February 23, 2021 -

edit: this is talking about making a PR if that isn't clear my bad

Assuming history doesn't matter/squash.

I find it much easier to:

  • clean up my dev branch/commit

  • checkout master

  • pull down latest master

  • checkout my dev branch again

  • do $git merge master

I do this because I've found the rebase method I had to go through each commit... possibly deal with conflicts more than once(per commit).

🌐
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.

🌐
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.
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › git merge master into branch
Git Merge Master into Branch {Two Methods Explained}
October 2, 2023 - Git is a version control system that allows users to work in several development lines called branches. The master (or main) branch is usually the default branch in a repository, created by default by the git init command. Although it is not usually the practice to merge the master branch into other branches, there are some exceptions to the practice.
Find elsewhere
🌐
Uidaholib
uidaholib.github.io › digital-collections-docs › content › maintainers › merging.html
Merging Main into Branch | Digital Collections Docs
If there are no conflicts, merge message will pop up, type Ctrl+X to save default message. If there are conflict, merge will stop and you will have to resolve the conflicts first (edit them in VS Code), then complete the merge commit. ... GitHub Desktop will list the conflicts you need to resolve before the merge can be committed.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-a-git-branch-into-master
How to Merge a Git Branch into Master? - GeeksforGeeks
May 22, 2024 - 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.
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
🌐
Reddit
reddit.com › r/git › merge branch to master
r/git on Reddit: Merge Branch to Master
July 11, 2025 -

0

I have very basic question and am very novice to GIT. Hence, my question is below.

I have "Master" as base branch where my code files and folders are. Now, I have 5 teammates, and they have created 5 branches separately to work on different folders cloning the masters. Now, my question is - I created some changes in folder xyz in my branch abc123. Now, I need to push my changes from abc123 branch and merge to Master. If I merge, then master repo will be updated with new changes. Now, my concern is that what if other teammates push their changes in to master working different folder called abc but in their cloned one in their branch there would be previous content of xyz content. will that previous content from his branch replace my updated one in master?

🌐
Atlassian
atlassian.com › git › tutorials › using branches › git merge
Git Merge | Atlassian Git Tutorial
Git merge will combine multiple sequences of commits into one unified history. In the most frequent use cases, git merge is used to combine two branches. The following examples in this document will focus on this branch merging pattern. In these scenarios, git merge takes two commit pointers, usually the branch tips, and will find a common base commit between them.
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.

🌐
Varonis
varonis.com › blog › git-branching-and-merging
Git Branching and Merging: A Step-By-Step Guide
September 12, 2025 - Once you merge the hotfix branch, continue working on the feature1 branch. As you continue making commits on the feature1 branch, the commit history diverges. Git is unable to move the pointer to the latest commit like in a fast-forward commit. To bring the feature1 branch into the main branch, Git performs a three-way merge.
🌐
FreeBSD
forums.freebsd.org › development › userland programming and scripting
Other - git: correct way to merge/pull commits/branches into master retaining history? | The FreeBSD Forums
September 4, 2024 - Or can one cherry-pick branches to pull in all commits from that branch? ... Git doesn't enforce a specific workflow, you're pretty free to do anything you want. From what you write, you probably want a "rebase and fast-forward merge" workflow (I personally think that's the sanest option anyways). Say you have some master branch you didn't touch so far, and your own branches feature_a and feature_b, then you'd do the following:
🌐
JanBask Training
janbasktraining.com › community › devops › how-do-i-safely-merge-a-git-branch-into-master
How do I safely merge a Git branch into master? | JanBask Training Community
September 3, 2025 - Always make sure your code passes tests and works as expected before merging. This step prevents introducing errors into master. ... In short, the safest way to merge is to keep your branch updated, resolve conflicts early, test your code, and then merge.
🌐
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.
🌐
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 - This command applies the changes from master into your branch. If there are no conflicts, Git will automatically merge the changes. If there are conflicts, you’ll need to resolve them manually in the affected files.
🌐
Graphite
graphite.com › guides › how-to-merge-branch-to-main-in-git
How to merge a Git branch into main
Learn the process of merging a branch into the main branch in Git, including preparatory steps, execution, and handling merge conflicts effectively.