Created
February 3, 2026 10:38
-
-
Save AhmedElwerdany/18f86d28c373e926f997b2a2c693306a to your computer and use it in GitHub Desktop.
Generate Git commit messages via ChatGPT (staged diff)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| diff="$(git diff --cached)" | |
| if [[ -z "$diff" ]]; then | |
| echo "No staged changes." | |
| exit 1 | |
| fi | |
| prompt=$(printf "Write a clear, professional Git commit message summarizing these changes. | |
| \n%s" "$diff") | |
| # Copy to clipboard | |
| if command -v wl-copy >/dev/null; then | |
| printf "%s" "$prompt" | wl-copy | |
| elif command -v xclip >/dev/null; then | |
| printf "%s" "$prompt" | xclip -selection clipboard | |
| elif command -v pbcopy >/dev/null; then | |
| printf "%s" "$prompt" | pbcopy | |
| fi | |
| # URL encode CORRECTLY | |
| encoded=$(printf "%s" "$prompt" | python3 -c 'import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read()))') | |
| # Open with prompt | |
| xdg-open "https://chatgpt.com/?prompt=$encoded" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation (Global Command)
Option 1 — Install to
/usr/local/bin(recommended)This makes
gitcommitgptavailable system-wide.# Download or save the script as: gitcommitgpt sudo mv gitcommitgpt /usr/local/bin/gitcommitgpt sudo chmod +x /usr/local/bin/gitcommitgptVerify:
Option 2 — Install to
~/.local/bin(no sudo)For user-only installation:
Ensure it’s in your PATH:
Reload shell:
Requirements
gitOne of:
xclip(X11)wl-copy(Wayland)pbcopy(macOS)python3Usage
Stages must already be added with:
git add .