[Git] How do I merge featured branch into master, when master have already be edited (e.g. bug fixes)

patarapolw profile image Pacharapol Withayasakpunt ・1 min read


I want to totally replace master, actually. But I would rather release / tag the stable code on GitHub first.

Is it about rebase, that I haven't tried?

I also haven't tried stash.

This also raises some general questions,

  • Where do you usually draw a flowchart? (I used PowerPoint, but it seems unprecise...)
  • How do you usually upload for dev.to?


markdown guide
# 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

Thanks. Here is what I do.

  • Merge "fixes" into "master" by making PR on GitHub.
  • Delete branch both on remote and local
git branch -d fixes
git remote prune origin
  • On local, checkout "feature" using VSCode, then merge "master"
$ git merge master
Auto-merging ***
CONFLICT (content): Merge conflict in ***
Automatic merge failed; fix conflicts and then commit the result.
  • Manual fix merge conflict, then add and commit
git add .
git commit
git push origin feature
  • Merge "feature" into "master" by making PR on GitHub.

In short, TIL git merge. I have never tried merging in local before. Not really how to fix merge conflict in remote. This might be related.


I would fear, that merging at different stages in history would cause conflict, that I have to manually fix.

Is it better to see this?

If you have questions, please
<<<<<<< HEAD
open an issue
ask your question in IRC.
>>>>>>> branch-a

Or, fix bugs in "feature" branch when it actually appears?


Well, fixing bugs and resolving conflicts is two different things.

  1. A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. Resolving conflicts is integral part of merging, you are expected to resolve conflicts when it happens.

  2. A bug is an error, flaw or fault in your software that causes it to produce an incorrect or unexpected result, or to behave in unintended ways. No one wants to fix bugs he doesn't own, but, you can merge any time from master, meaning, you can assume that some point on master was stable, and I would count on that and merge that point of time into your branch. (could be after the bug was fixed or before the bug existed)

Does it make sense?


I want to totally replace master, actually.

This is a not recommended action, but it is possible. Github probability prevents force push to master (gitlab does)

If you just want feature added to master, the a merge request will suffice if there are no conflicts (do not avoid conflicts).

If there is conflict there are two options.

1 rebase onto master
2 Merge master into feature branch