Just pass the -m and --no-ff parameters to the merge command:

$ git merge other-branch -m "Commit Message" --no-ff

The --no-ff parameter is required to prevent merging as a fast-forward without merge commit.

Answer from Joe Zim on Stack Overflow
Top answer
1 of 6
129

Just pass the -m and --no-ff parameters to the merge command:

$ git merge other-branch -m "Commit Message" --no-ff

The --no-ff parameter is required to prevent merging as a fast-forward without merge commit.

2 of 6
20

You basically have two option.

Easy solution: don't merge, Rebase
Rebase your branch on top of the main branch, resolve conflict, and then merge. As you'll have a straight history, you'll be able to fast-forward to merge and this won't create any merge commit.

git checkout feature
git rebase main
# Resolve conflict if there is
git checkout main
git merge feature

Second option: Rebase -i
You can edit your history after your merge (before you push to a remote). You can manage this with rebase interactive mode.

git checkout main
git merge feature
#You merge and resolve conflict
git rebase -i <sha of the commit before the merge>

Then you'll be taken into an interactive shell with the list of the commits, e.g.:

pick 73c991e Create progress bar module
pick b8a0b83 merge branch feature
pick 2120f47 Add user form
pick 70c55e4 Quiz prototype system

You just need to add squash or s instead of pick:

pick 73c991e Create progress bar module
pick b8a0b83 merge branch feature
s 2120f47 Add user form
pick 70c55e4 Quiz prototype system

This command would squash together b8a0b83 and 2120f47. The next step will be a commit text editor where you have both commit message combined, and it's now up to you to edit them correctly to only keep your original message.

🌐
Git
git-scm.com › docs › git-merge
Git - git-merge Documentation
Assume the following history exists and the current branch is master: ... Then git merge topic will replay the changes made on the topic branch since it diverged from master (i.e., E) until its current commit (C) on top of master, and record the result in a new commit along with the names of ...
Discussions

git - What produces a commit message like: Merge branch 'master' of ... into 'master' - Stack Overflow
How is this kind of commit message produced? Merge branch 'master' of https://github.com/AAA/BBB into 'master' More on stackoverflow.com
🌐 stackoverflow.com
git - Merge branch 'master' of https://github.com/... in commit message - Stack Overflow
When git pull runs git merge, it supplies, as the merge commit's log message: ... The part is the name of the branch that git pull told git fetch to get from the other Git. The part is the URL that git pull told git fetch to contact, to get commits found via the name . So if your branch has origin/master ... More on stackoverflow.com
🌐 stackoverflow.com
Mysterious commit: Merge branch 'master' of https://github.com/my_account/my_repo
This is caused when your local repo is both ahead and behind your remote repo, and you perform a "git pull" command. This can easily happen if you work from more than one local repo, or if you collaborate with other developers. If you want to avoid these dumb-looking merge commits, you need to explicitly resolve the conflict in a different way. One easy way to do this is to always do "git pull --rebase" instead of "git pull", which will rebase your local commits on top of your remote commits, instead of creating a merge commit. You can configure your local Git to perform this kind of pull by default if you like. More on reddit.com
🌐 r/git
7
1
November 8, 2018
Can't enter commit message in Git after merging branch. Any advice?
You were thrown into your default editor, most likely vi. git config --global core.editor nano is probably more useful and easier to navigate for you. More on reddit.com
🌐 r/git
3
5
July 25, 2022
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
(use "git commit" to conclude merge) Changes to be committed: modified: index.html · If you’re happy with that, and you verify that everything that had conflicts has been staged, you can type git commit to finalize the merge commit. The commit message by default looks something like this:
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git merge
Git Merge | Atlassian Git Tutorial
In these scenarios, git merge takes two commit pointers, usually the branch tips, and will find a common base commit between them. Once Git finds a common base commit it will create a new "merge commit" that combines the changes of each queued ...
🌐
30 Seconds of Code
30secondsofcode.org › home › git › repository › merge branch
Merge a branch in Git - 30 seconds of code
May 26, 2023 - # Syntax: # git checkout <target-branch> # git merge --no-ff -m <message> <source-branch> git checkout master git merge --no-ff -m "Merge patch-1" patch-1 # Merges the `patch-1` branch into `master` and creates a commit # with the message "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 - Replace "Your merge commit message" with the message you want to use for the merge commit. Enclose the message in double quotes. [source_branch] is the name of the branch you want to merge into your current branch.
Find elsewhere
🌐
DedicatedCore
dedicatedcore.com › home › how to safely merge a git branch into master
How to Safely Merge a Git Branch into Master - DedicatedCore Blog
October 31, 2024 - The command automatically changes the commit message to the one enclosed in double quotes and merges the examplebranch branch into the master branch.
🌐
CodeGenes
codegenes.net › blog › get-changes-from-master-into-branch-in-git
How to Merge Master Changes Into a Git Branch: Best Practices & Step-by-Step Guide — codegenes.net
First, confirm you’re on the ... git switch feature/shopping-cart (Git 2.23+) ... Commit them: git add . && git commit -m "Your commit message" Or stash them: git stash save "Stashing before merging master"...
🌐
Stack Abuse
stackabuse.com › git-merge-branch-into-master
Git: Merge Branch into Master
April 20, 2023 - To summarize, here are the commands ... # ...develop some code... $ git add . $ git commit –m "Some commit message" $ git checkout master $ git merge new-branch...
🌐
W3Schools
w3schools.com › git › git_branch_merge.asp
Git Branch Merge
Since the emergency-fix branch came directly from master, and no other changes had been made to master while we were working, Git sees this as a continuation of master. So it can "Fast-forward", just pointing both master and emergency-fix to the same commit. Always commit or stash your changes before starting a merge. Regularly merge from the main branch into your feature branch to minimize conflicts. Read and resolve conflicts carefully-don't just accept all changes blindly. Write clear and descriptive merge commit messages.
Top answer
1 of 1
7

The command git pull, which at least one of you two used, runs two other Git commands for you. (I'll refer here to "you", but this could be the other engineer, or you two may be taking turns. Think of "you" as standing for "you all" or "both of you", even though only one of you runs each command at a time.)

The first command that git pull runs for you is always git fetch. This obtains commits from another Git repository. Specifically, it uses the repository you name—or origin by default—to find commits that they have that you don't have, presumably because those commits were added to their repository after you ran git clone. Git puts those commits into your copy of the repository, so now you have them too.

The second command that git pull runs is usually git merge (you can set it up to run a different second command, but obviously you have not done that). When git pull runs git merge, it supplies, as the merge commit's log message:

Merge branch '<name>' of <url>

The <name> part is the name of the branch that git pull told git fetch to get from the other Git. The <url> part is the URL that git pull told git fetch to contact, to get commits found via the name <name>. So if your branch has origin/master set as its upstream, your git pull has your Git call up the Git at origin and get any new commits from that Git's master. Then your git pull has your Git merge those commits, with the message Merge branch 'master' of ....

At this point, you have their (the other Git's) commits and your own commits, plus a merge commit tying your two sets of commits together. Assuming you are using your own master, this looks something like this:

          ●--●--●
         /       \
...--o--o         ●   <-- master (HEAD)
         \       /
          o-----o   <-- origin/master

Your commits—the ones you made yourself—are along the top row; the shared commits are at the left middle row; and their commits—the ones they made after you cloned—are along the bottom row. The right-most commit is the new merge commit you just made. I have marked the commits that you have, that they don't, as solid black circles .

You now run git push origin master to send your new commits to the Git at origin, on GitHub. This sends the commits that yo have that they don't, and then asks GitHub's Git to set its master to point to the merge commit. If it does so, your Git remembers this, so that your own diagram now looks like this:

          ●--●--●
         /       \
...--o--o         ●   <-- master (HEAD), origin/master
         \       /
          o-----o

When someone else runs git fetch to the Git on GitHub that holds the other copy, GitHub's Git's master will now point to this same final commit, so you'll see Merge branch 'master' of <url> as the log message of the tip-most commit of this master.


When thinking about all this, remember that there are three Git repositories involved here now. There's GitHub's Git, holding a copy of the repository that you update by using git push. There's your co-worker's Git, holding a copy of the repository that your co-worker updates from GitHub, and that your co-worker uses git push to send updates to GitHub. And there's your own Git, holding a copy of the repository you got from GitHub, where you use git push to send your updates to GitHub. GitHub's third repository simply acts as the sharing point.

🌐
Reddit
reddit.com › r/git › mysterious commit: merge branch 'master' of https://github.com/my_account/my_repo
r/git on Reddit: Mysterious commit: Merge branch 'master' of https://github.com/my_account/my_repo
November 8, 2018 -

Hi all. Into the master branch on my local repo, I occasionally pull changes from my remote repo. I just noticed that in my local repo commit log, whenever those pulls occur, sometimes a second commit occurs, with the message:

Merge branch 'master' of https://github.com/cagross/els

screenshot. FYI the URL in the error message is indeed the correct URL to my remote repo--I've modified it here for security.

What exactly is causing this commit, and what is the reason? These aren't commits that I have explicitly made. Rather, I certainly didn't explicitly make a commit with that commit message. Does git automatically create a commit like this when a merge (or other related action) occurs?

This doesn't seem to occur for every pull that occurs.

The reason I ask is because I would like my local repo to remain in-sync with my remote repo. But git status indicates that my local repo is ahead of my remote repo by several commits, and most of those are due to the mysterious commits that I've mentioned here.

Thanks in advance.

🌐
Mrvirk
mrvirk.com › home › how to fix ? please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch issue
How to Fix ? Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch issue - The Virk Report by Virk & Co.
May 4, 2026 - When trying to push a commit into Github via terminal we come across this problem: “Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch | Error Message”.
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
🌐
JavaScript in Plain English
javascript.plainenglish.io › problem-with-git-merge-please-enter-a-commit-message-to-explain-why-this-merge-is-necessary-854757988c17
Problem with a Git Merge: Please enter a commit message to explain why this merge is necessary | JavaScript in Plain English
June 7, 2020 - Merge branch 'master' of https://github.com/marieqg/netlify-cms-medium # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch.