Fixing the “Commit Message Missing Valid Issue Key” Git Error

One of your commit messages is missing valid issue key

Encountering the “One of your commit messages is missing a valid issue key” error after a git push can be frustrating. Fortunately, it’s usually a simple fix. Let’s walk through the steps to resolve this issue and successfully push your code.

Bash
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 10 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 865 bytes | 865.00 KiB/s, done.
Total 9 (delta 6), reused 0 (delta 0), pack-reused 0
remote: 
remote: One of your commit messages is missing a valid issue key:
remote: 
remote:   cbfb6e6: feature/dhi-1490:added inbound rules
remote: 
remote: For more information, see https://support.atlassian.com/bitbucket-cloud/docs/link-to-a-web-service/
To bitbucket.org:ShopDirect/ds-terraform-pbi-infrastructure.git
 ! [remote rejected] feature/dhi-1490-Add-RDP-Inbound -> feature/dhi-1490-Add-RDP-Inbound (pre-receive hook declined)
error: failed to push some refs to 'bitbucket.org:{MY_PRIVATE_REPO}/{MY_PRIVATE_REPO}infrastructure.git'

Discrepancies in repo rules cause this error. You can see what your rules are by viewing your repository settings. I use Bitbucket so its in Repo > Settings > Repository Links

If you don’t have access to this part of the repo, the easiest thing to do is check previous commit logs to see how everyone else has written their commit message.

Understanding the Missing Valid Issue Key Error

This error typically arises when your Git repository is configured to enforce certain rules for commit messages. These rules often require linking commit messages to specific issue-tracking systems like Jira or Bitbucket Issues. If your commit message doesn’t adhere to these rules, the push is rejected.

Step 1 – View the Git Log.

View the previous git commits and look for the problem. My issue was that i had a rule that required the JIRA ticket to be in UPPER case, my initial commit was in lower case. I worked this out by reviewing other commit messages in the log.

Bash
git log

For Example:

Bash
commit bd2846e70c417d9de4e1dcca763ddbb85328b14d (HEAD -> feature/dhi-1490-Add-RDP-Inbound, origin/feature/dhi-1490-Add-RDP-Inbound)
Author: Richard Bailey <[email protected]k>
Date:   Thu Sep 29 13:56:31 2022 +0100

    feature/dhi-1490:added inbound rules

commit b48f4960a85dc24c840c00e822752917ebbe07b9 (origin/master, origin/HEAD, master)
Merge: a982cdc 378c1db
Author: Colleague 1 <[email protected]k>
Date:   Wed Aug 3 10:13:57 2022 +0000

    Merged in feature/DHI-1119 (pull request #55)
    
    Feature/DHI-1119
    
    Approved-by: Colleague3
    Approved-by: Colleague4

If you compare the above you will see that my commit bd2846e70c417d9de4e1dcca763ddbb85328b14d was written in lower case, but commit b48f4960a85dc24c840c00e822752917ebbe07b9 was in upper.

Step 2 – Soft Reset the Git Header.

Bash
git reset --soft HEAD~1 

Step 3 – Proceed to Recommit Your Work

Bash
git add .
commit -a -m'Feature/DHI-1490-my-commit-message'
git push

The code should now commit.

Example (Bitbucket)

In Bitbucket, if you have a rule requiring JIRA issue keys in uppercase, a commit message like feature/dhi-1490:added inbound rules would fail. You’d need to amend it to Feature/DHI-1490: Added inbound rules (capitalized “DHI”).

Important Note:

Avoid force pushing (git push -f) unless absolutely necessary, as it can overwrite others’ work and disrupt collaboration.

Additional Tips:

  • Configure your code editor or IDE to automatically insert the correct issue key format in commit messages.
  • If the issue persists, consult your repository administrator or the documentation of your Git hosting platform.

Here’s how you can configure WebStorm and VS Code to automatically insert issue key formats in your commit messages:

WebStorm: Missing Valid Issue Key

  1. Install the Jira Plugin:
    • Go to File > Settings > Plugins.
    • Search for “Jira” and install the official JetBrains Jira plugin.
    • Restart WebStorm.
  2. Link Your Jira Account:
    • In the Tools menu, you should now see a Tasks & Contexts option.
    • Click on it and select Open Task.
    • Follow the prompts to connect your Jira account.
  3. Configure Commit Message Template:
    • Go to File > Settings > Version Control > Commit Dialog.
    • In the “Commit Message” section, you can customize the template:
      • Use {task} to automatically insert the Jira issue key.
      • Add any other relevant text, like “Fixes” or “Implements.”

Example Template:

Bash
{task} - {summary}

Now, when you commit in WebStorm, the plugin will automatically insert the linked Jira issue key and summary into your commit message.

VS Code: Missing Valid Issue Key

  1. Install an Extension:
    • Several extensions offer commit message templates. Here are a few popular options:
      • Git Commit Template
      • Commit Message Editor
      • Conventional Commits
  2. Configure the Template:
    • After installing your chosen extension, go to File > Preferences > Settings.
    • Search for the extension’s settings.
    • Look for a setting like “Template” or “Format” and customize it to your liking.

Example Template:

Bash
[<ISSUE_KEY>] - <Short description of changes>

Now, when you commit in VS Code, you can use the extension’s command or shortcut to insert the template, prompting you to enter the issue key and description.

General Tips:

  • Consistency is Key: Ensure your team agrees on a standard format for issuing keys and committing messages.
  • Customization: Adapt the templates to match your project’s specific workflow and requirements.
  • Branch Naming: For even clearer tracking, consider using branch names that include the issue key (e.g., “feature/DHI-1490”).

Check out more Tech Quickys here.

Thanks for taking the time to read this article. if you have any questions or feedback, please write in the comment section below.

Elsewhere On TurboGeek:  How to manage Terraform State

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

1 Response

  1. Subramaniam says:

    This works perfect and flawless. I tried so many options given in stack overflow and other sites and nothing worked for me except your suggestion.
    Thank you lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »