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 Answer from Buxbaum666 on reddit.com
🌐
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.

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 4
21

I merged master branch into my feature-branch and resolved conflicts.

git checkout master
git pull
git checkout feature-branch
git merge master

This didn't disturb any of the comment history in existing sub-branches of my feature-branch.

I did rebase the sub-branches on top of the feature-branch(with latest changes) and all looks fine.

2 of 4
7

Let's try to answer this with a couple of general illustrations, since we don't know exactly how your particular case look like. First of all, let's agreeing on how merge and rebase differs, before looking at the case your are asking for, where multiple feature branches based on each other.

As you are probably aware merge preserves history as it happened, while rebase rewrites it. The difference can be seen in above illustration.

Now, let's try to answer your initial question with a similar illustration; where two feature branches (feature-1 & feature-2) are based on each other, and currently trails behind master.

Regardless of how you decide to integrate the changes from master into feature-1 (merge or rebase), feature-2 will be left as is (i.e. without the newly integrated changes from master into feature-1). If you then want to integrate all changes into feature-2 you are once again left with the option of merging or rebasing.

If you would decide to rebase feature-2 onto feature-1 (post the initial master integration) Git would then figure out that commits ol42g and 09qr2 are already present, and hence automatically strip those patches out from your rebased version of feature-2.

A cautionary warning: Rebasing branches that have already been published can cause headaches for your team mates, so make sure to keep a tight dialog if that would be the case. To stay on the safe side, don't rebase branches that are already publicly available.

Hopefully it should be clear now what your options are. =)

🌐
Reddit
reddit.com › r/git › what does it mean to merge master into feature branch?
r/git on Reddit: What does it mean to merge master into feature branch?
October 1, 2020 -

In advance, I'm new to Git and GitHub and I'm sorry if this is a silly question AND if this is the wrong place to post this.

My boss said, "don't forget to merge master back into the feature branch before making new PRs so I don't have to go through all the changes."

So, the following is my flow:

- Create a fork of the company Repo (only once, and obviously not every time)

- Checkout a branch

- Git add .

- Git commit

- Git push origin <branch name>

- Go into GitHub and make a PR and assign it to my boss

My assumption was that the boss wanted to merge with the master himself. However, is he asking me to do it?

🌐
git-knowledge-base
idiv-biodiversity.github.io › git-knowledge-base › how-to-integrate-master-in-feature.html
how to integrate changes: from master to feature branch | git-knowledge-base
This should be done when the feature branch is finally merged back into master with either a squash and merge or a rebase and merge (TODO: add links). $ git checkout topic/feature Switched to branch 'topic/feature' $ git merge --no-edit master Merge made by the 'recursive' strategy.
🌐
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 › how-to-merge-a-git-branch-into-master
How to Merge a Git Branch into Master? - GeeksforGeeks
May 22, 2024 - Regularly Merge Master into Feature Branches: This minimizes the risk of conflicts and keeps your feature branch up-to-date. Commit Frequently: Smaller, frequent commits are easier to manage and less likely to cause conflicts. Write Clear Commit Messages: Good commit messages make it easier to understand the history of changes. Use Pull Requests: For collaborative projects, pull requests provides code review and discussion before merging. Merging a Git branch into master is an important task that ensures your project stays on track.
🌐
DEV Community
dev.to › patarapolw › git-how-do-i-merge-featured-branch-into-master-when-master-have-already-be-edited-e-g-bug-fixes-1aka
[Git] How do I merge featured branch into master, when master have already be edited (e.g. bug fixes) - DEV Community
April 7, 2020 - # merge master first into your branch git checkout feature-x git merge master # merge your branch into master git checkout master git merge feature-x # or: git merge --squash feature-x
Find elsewhere
🌐
Reddit
reddit.com › r/git › merging master branch into feature branch
r/git on Reddit: Merging master branch into feature branch
October 14, 2021 -

Hi folks,

I'd like to hear you about something that bothers me every time I see.

Often I see someone merging the master branch into a feature branch in order to update it with the last changes.

My understanding is the most appropriated would be to *rebase* the feature branch, so the branch history don't get dirty with a lot of meaningless merge commits.

Moreover, any rebase operation on the feature branch (maybe for change a commit message or for squash commits) becomes a nightmare when these merge commits are on the tip of the feature branch.

Does anybody has a good tech reason for not merging master into feature branches or am I just being annoying?

🌐
SoftwareTestingo
softwaretestingo.com › home › tools › git › git merge command
Git Merge From Branch Master Into Feature Branch [ 2026 ]
January 6, 2024 - There’s a linear path from our feature branch back to the master. To merge the changes to the main branch, all you have to do is change the pointer of the master forward. This is called a fast-forward merge. git init echo hello>hello.txt git add .
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
🌐
Dheerajjha
dheerajjha.com › blog › git-merge-feature-guide
How to Successfully Merge the Main Branch into Your Feature Branch: A Complete Guide | Dheeraj Jha
October 25, 2025 - The --no-ff flag creates a merge commit even if the merge could be fast-forwarded, preserving branch history. If there are conflicts, Git will notify you. Resolve any conflicts, then add the resolved files: ... Check your key features and files to make sure they're preserved.
🌐
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 11
1632

How do we merge the master branch into the feature branch? Easy:

git checkout feature1
git merge master

There is no point in forcing a fast forward merge here, as it cannot be done. You committed both into the feature branch and the master branch. Fast forward is impossible now.

Have a look at GitFlow. It is a branching model for git that can be followed, and you unconsciously already did. It also is an extension to Git which adds some commands for the new workflow steps that do things automatically which you would otherwise need to do manually.

So what did you do right in your workflow? You have two branches to work with, your feature1 branch is basically the "develop" branch in the GitFlow model.

You created a hotfix branch from master and merged it back. And now you are stuck.

The GitFlow model asks you to merge the hotfix also to the development branch, which is "feature1" in your case.

So the real answer would be:

git checkout feature1
git merge --no-ff hotfix1

This adds all the changes that were made inside the hotfix to the feature branch, but only those changes. They might conflict with other development changes in the branch, but they will not conflict with the master branch should you merge the feature branch back to master eventually.

Be very careful with rebasing. Only rebase if the changes you did stayed local to your repository, e.g. you did not push any branches to some other repository. Rebasing is a great tool for you to arrange your local commits into a useful order before pushing it out into the world, but rebasing afterwards will mess up things for the git beginners like you.

2 of 11
666

You should be able to rebase your branch on master:

git checkout feature1
git rebase master

Manage all conflicts that arise. When you get to the commits with the bugfixes (already in master), Git will say that there were no changes and that maybe they were already applied. You then continue the rebase (while skipping the commits already in master) with

git rebase --skip

If you perform a git log on your feature branch, you'll see the bugfix commit appear only once, and in the master portion.

For a more detailed discussion, take a look at the Git book documentation on git rebase (https://git-scm.com/docs/git-rebase) which cover this exact use case.

================ Edit for additional context ====================

This answer was provided specifically for the question asked by @theomega, taking his particular situation into account. Note this part:

I want to prevent [...] commits on my feature branch which have no relation to the feature implementation.

Rebasing his private branch on master is exactly what will yield that result. In contrast, merging master into his branch would precisely do what he specifically does not want to happen: adding a commit that is not related to the feature implementation he is working on via his branch.

To address the users that read the question title, skip over the actual content and context of the question, and then only read the top answer blindly assuming it will always apply to their (different) use case, allow me to elaborate:

  • only rebase private branches (i.e. that only exist in your local repository and haven't been shared with others). Rebasing shared branches would "break" the copies other people may have.
  • if you want to integrate changes from a branch (whether it's master or another branch) into a branch that is public (e.g. you've pushed the branch to open a pull request, but there are now conflicts with master, and you need to update your branch to resolve those conflicts) you'll need to merge them in (e.g. with git merge master as in @Sven's answer).
  • you can also merge branches into your local private branches if that's your preference, but be aware that it will result in "foreign" commits in your branch.

Finally, if you're unhappy with the fact that this answer is not the best fit for your situation even though it was for @theomega, adding a comment below won't be particularly helpful: I don't control which answer is selected, only @theomega does.

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

🌐
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 exceptions for merging the master into another branch are when you need to merge a hotfix or a new release branch. There are two methods you can use: git merge.
🌐
Stack Abuse
stackabuse.com › git-merge-branch-into-master
Git: Merge Branch into Master
April 20, 2023 - First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch.
🌐
Reddit
reddit.com › r/git › merging master branch to feature branch and then pushing to new repo
r/git on Reddit: Merging master branch to feature branch and then pushing to new repo
June 18, 2023 -

I have a feature branch checked out on which I have made many changes that I havent pushed to master yet. Out repo was on gitlab, but it has locked out because we exceeded max user limits. So we cannot push to this repo anymore, though we can pull. Now the team has decided to move to github and it might take some time to move the repo to github.

My doubt is can I merge master branch to feature branch locally and then commit it to github once the migration from gitlab to github completes? If yes, can you please give some overview of the process or at least link of some webpage discussing the same?

🌐
Namehero
namehero.com › blog › how-to-merge-a-git-branch-to-master
How to Merge a Git Branch to Master
October 6, 2025 - You don’t want to accidentally merge the new branch into an outdated version of the main branch. So always ensure that you have the most recent copy by using the following command: ... This will get the most recent copy of the main branch. We’re ready to merge! Type the following command: ... As long as there are no conflicts, you can see that git merges the changes you made in the feature branch into main.