Skip to content

Instantly share code, notes, and snippets.

@lionrajkumar
Created March 3, 2025 16:06
Show Gist options
  • Select an option

  • Save lionrajkumar/0a1e6b4a59f457e72ff63692756c4449 to your computer and use it in GitHub Desktop.

Select an option

Save lionrajkumar/0a1e6b4a59f457e72ff63692756c4449 to your computer and use it in GitHub Desktop.
Git to control whether Git opens the default editor during a merge commit.

You can set the GIT_MERGE_AUTOEDIT environment variable in Git to control whether Git opens the default editor during a merge commit. Here's how you can do it:

Temporarily (for the current session)

Run this command in your terminal:

export GIT_MERGE_AUTOEDIT=no  # Prevents Git from opening the editor

or

export GIT_MERGE_AUTOEDIT=yes  # Allows Git to open the editor

This setting will only last until you close the terminal session.

Permanently (for all sessions)

To make this setting permanent, add the export command to your shell configuration file:

  • For Bash (~/.bashrc or ~/.bash_profile):
    echo 'export GIT_MERGE_AUTOEDIT=no' >> ~/.bashrc
    source ~/.bashrc
  • For Zsh (~/.zshrc):
    echo 'export GIT_MERGE_AUTOEDIT=no' >> ~/.zshrc
    source ~/.zshrc

Windows (Command Prompt or PowerShell)

  • Command Prompt (cmd):
    set GIT_MERGE_AUTOEDIT=no
  • PowerShell (temporary):
    $env:GIT_MERGE_AUTOEDIT = "no"
  • PowerShell (permanent in profile script):
    [System.Environment]::SetEnvironmentVariable("GIT_MERGE_AUTOEDIT", "no", "User")

Now, Git will automatically skip opening the editor during merge commits if set to no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment