Fixing a common problem with a Git Merge

Please enter a commit message to explain why this merge is necessary

I recently finished working on this article on how to create a blog with Netlify as a CMS. While working on this article, I tried to make a merge and ended up not being able to. I had this message:

Merge branch 'master' of [https://github.com/marieqg/netlify-cms-medium](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.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
~
~
"~/Documents/Projets/medium/netlify-cms-medium/.git/MERGE_MSG" 6L, 297C

It’s not the first time I had it, but it was sure the last time. And I was stuck there for a while again. They are a few methods to go out of this depending on the editor that you are using.

Step 1: Understand why

Firstly, let’s try to understand why we got this message.

There a few options :

  • This happens when a commit was made to the branch you are working on (you try to push a commit: git push) before pulling the changes ( git pull)

  • You updated your git client

  • You never had a local branch which was ahead of the remote before

  • Your git config was changed recently

  • You should have done git rebase or git pull --rebase instead of a merge

Most of the time when I get this message, it’s because I forgot to pull before I pushed and my branches get confused. Photo by Maddy Baker on UnsplashMost of the time when I get this message, it’s because I forgot to pull before I pushed and my branches get confused. Photo by Maddy Baker on Unsplash

Step 2: Finalize your merge

Then, let’s solve it to finalize our merge. The way to solve it is going to depend on our editor. So:

1. For Vi or Vim

If you are using vi or vim, to manage to get out, you’ll have to do :

  1. Press “i” (i for insert)

  2. Write your merge message

  3. Press “esc” (escape)

  4. Write “:wq” (write & quit)

  5. Then press enter

Personally, it’s the one I’m using (let’s not get into a developer argument on which editor to use right?), and this worked quite well for me.

2. For Pico, Nano or Emac

If you are using Nano, you’ll have to do:

  • CTRL + X

  • then, CTRL + C

For nano, a CTRL + C might be sufficient.

It’s as easy as this, but I always struggle with this one.

🕵️‍♂️ Resources to go further

Please enter a commit message to explain why this merge is necessary, especially if it merges an…

Fix: Please enter a commit message to explain why this merge is necessary - Appuals.com

Git - When to Merge vs. When to Rebase

👏 If you liked this article feel free to follow me to receive similar content in the future.

📚 Also, if you want to learn more, you can take a look at those articles:

How to do a contact form step by step with Gatsby.js, Netlify and Mailgun

How to connect your Gatsby.js landing page to Google Analytics and deploy to Netlify step by step

How to create a newsletter with Mailchimp, Gatsby.js & Netlify

Enjoyed this article?

Share it with your network to help others discover it

Continue Learning

Discover more articles on similar topics