logo

How to Add 'Publish to Github' to Windows Context Menu

O

Ohidur Rahman Bappy

MAR 22, 2025

How to Add 'Publish to Github' to Windows Context Menu

Overview

This guide will help you add a 'Publish to Github' option to your Windows context menu, enabling quick access to publishing directories or files to your GitHub repository.

Where to Create Context Menu Entry?

  • FILES
    HKEY_CURRENT_USER\Software\Classes\*\shell\
    Opens on a file

  • DIRECTORY
    HKEY_CURRENT_USER\Software\Classes\Directory\shell
    Opens on a directory

  • DIRECTORY_BACKGROUND
    HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell
    Opens on the background of the Directory

  • DRIVE
    HKEY_CURRENT_USER\Software\Classes\Drive\shell
    Opens on the drives (e.g., USBs)

Python Script for Committing

Below is a script to automate the committing process:

import subprocess
import os
import re
import unicodedata

USER_NAMESPACE="YOUR_USER_NAME_HERE"

def slugify(value, allow_unicode=False):
    value = str(value)
    if allow_unicode:
        value = unicodedata.normalize('NFKC', value)
    else:
        value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
    value = re.sub(r'[^\w\s-]', '', value)
    return re.sub(r'[-\s]+', '-', value).strip('-_')

if os.path.exists(os.path.join(os.getcwd(),'.git')):
    print("ERROR: Git repo already exists")
    exit(0)
current_folder_name=os.path.basename(os.getcwd())
current_folder_name=slugify(current_folder_name)

subprocess.run('git init -b main')
subprocess.run('git add .')
subprocess.run('git commit -m "Auto Publish"')
cmd='git push --set-upstream git@gitlab.com:'+USER_NAMESPACE+'/'+current_folder_name+'.git main'
subprocess.run(cmd)
print("SUCCESS!")
input()

Adding to Context Menu

Add a context menu item for all directories or files in Windows with these registry files:

For Directories

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script]
@="&Run Batch script"

[HKEY_CLASSES_ROOT\Directory\shell\Run Batch script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""

For Individual Files

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Run script]
@="Run &script"

[HKEY_CLASSES_ROOT\*\shell\Run script\command]
@="\"H:\\BATCH_FILE_PATH\\context-batch.bat\" \"%1\""

Add to 'Send To' List

Create a shortcut to your batch script and place it under %APPDATA%\Microsoft\Windows\SendTo (or enter shell:sendto into the address bar).

For Directory Background

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script]
@="&Run Batch script"
"Icon"="%SystemRoot%\\System32\\shell32.dll,71"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Run Batch script\command]
@="H:\\BATCH_FILE_PATH\\context-batch.bat \"%V\""

Advanced Context Menu Options

Creating a Basic Context Menu Option

Example: Add an option called Open Command Prompt.

  1. Create a new key under the shell key.
  2. Name the key as "Open Command Prompt".
  3. Add a subkey named command.
  4. Set the default value of command to cmd.exe.

Adding an Icon

  1. Add a String Value called Icon to the base key.
  2. Set its value to the path of the .ico file.

Creating Cascading Context Menus

Create nested context menus:

  1. Create a base key in the desired location.
  2. Add a String Value called MUIVerb with the base key's display name.
  3. Add a String Value named subcommands.
  4. Create a shell key under the base key.
  5. Create sub-menus by repeating the steps above.

Repeat these steps to create nested cascading menu options and customize as needed.