A command-line tool to enhance your Git workflow with AI-powered features, including automated Pull Request and commit message generation.
This tool analyzes your local Git changes, uses AI (via OpenAI) to generate relevant content, and integrates with Git and GitHub commands.
- Pull Request Generation (
generate pr
):- Analyzes committed changes between your current branch and a base branch (default:
main
). - Generates PR title and body using AI.
- Prompts to push the current branch if it doesn't exist on the remote.
- Optionally opens the created PR in your browser.
- Analyzes committed changes between your current branch and a base branch (default:
- Commit Message Generation (
generate commit
):- Analyzes staged changes to generate a conventional commit message (title and body with bullet points).
- Handles unstaged changes with user prompts or automatic staging via an option.
- General:
- Allows reviewing and editing all 8000 AI-generated content before finalizing.
- Supports multiple languages for content generation.
- Checks for prerequisites (
git
,gh
installed and authenticated,OPENAI_API_KEY
set). - Uses spinners and colored output for a better user experience.
- Git: Must be installed. git-scm.com
- GitHub CLI (
gh
): Must be installed and authenticated. Rungh auth login
after installation. cli.github.com - OpenAI API Key: You need an API key from OpenAI. platform.openai.com/api-keys
- Editor Configuration: The CLI uses your default text editor for editing the PR body. Make sure the
EDITOR
environment variable is set (e.g.,export EDITOR=nano
orexport EDITOR=\"code --wait\"
).
npm install -g gitmagic
yarn global add gitmagic
pnpm add -g gitmagic
bun add -g gitmagic
- Clone the repository:
git clone https://github.com/arthurbm/gitmagic.git cd gitmagic
- Install dependencies and build:
# Using npm npm install npm run build # Using yarn yarn yarn build # Using pnpm pnpm install pnpm build # Using bun bun install bun run build
- Link the CLI for local use:
This makes the
# Using npm npm link # Using yarn yarn link # Using pnpm pnpm link -g # Using bun bun link
gitmagic
command available in your terminal.
- OpenAI API Key: Set the
OPENAI_API_KEY
environment variable:(Add this to yourexport OPENAI_API_KEY=\"your_openai_api_key_here\"
~/.zshrc
,~/.bashrc
, or equivalent for persistence). - Editor: Ensure the
EDITOR
environment variable is set as mentioned in Prerequisites.
You can configure default options by creating a configuration file in your project directory or any parent directory. The tool uses cosmiconfig
and will automatically look for:
.gitmagicrc
(YAML or JSON).gitmagicrc.json
.gitmagicrc.yaml
.gitmagicrc.yml
.gitmagicrc.js
(ESM or CJS).gitmagicrc.cjs
gitmagic.config.js
(ESM or CJS)gitmagic.config.cjs
- A
"gitmagic"
key in yourpackage.json
.
Example `.gitmagicrc.json:**
{
"baseBranch": "develop",
"model": "gpt-4.1-mini",
"skipConfirmations": false,
"language": "portuguese"
}
Example `.gitmagicrc.js:**
module.exports = {
baseBranch: 'develop',
model: 'gpt-4.1-mini',
language: 'spanish',
};
Command-line arguments (e.g., --base main
) will always override settings from the configuration file.
- Navigate to a Git repository directory.
- Make sure you are on the feature branch you want to create a PR from.
- Ensure your desired changes are committed to the branch.
- Run the command:
gitmagic generate pr
- You can specify different options with command line arguments:
# Generate PR content in Portuguese gitmagic generate pr --language portuguese # Use a different model gitmagic generate pr --model gpt-4o # Change base branch gitmagic generate pr --base develop # Skip confirmations gitmagic generate pr --yes # Combine multiple options gitmagic generate pr --language spanish --model gpt-4o --base develop --yes
The tool will guide you through the process:
* For generate pr
:
* Checking prerequisites.
* Analyzing commits against the base branch (main
by default).
* Pushing the branch if needed (with confirmation).
* Generating PR content with AI in your specified language (English by default).
* Allowing you to review, edit, or confirm the content.
* Creating the PR on GitHub.
* Asking if you want to open the PR in the browser.
- Navigate to a Git repository directory.
- Stage the changes you want to include in the commit (
git add <file>...
orgit add .
). - Run the command:
gitmagic generate commit
- You can specify different options with command line arguments:
# Automatically stage all modified/deleted files before generating commit message gitmagic generate commit -a # Use a different model for commit message generation gitmagic generate commit --model gpt-4o # Generate commit message in a specific language (e.g., for commit conventions in other languages) gitmagic generate commit --language portuguese # Skip confirmation prompts gitmagic generate commit --yes
The tool will guide you through the process:
* For generate commit
:
* Checking for staged changes.
* If no staged changes, it may prompt to stage unstaged changes (unless --yes
or -a
is used).
* Generating a commit message with AI, including a concise title and a detailed body in bullet points, based on your staged changes.
* Allowing you to review and edit the title and body separately.
* Committing the changes with the generated (or edited) message, formatted with the title on the first line, followed by a blank line and then the body.
- Linting/Formatting: Uses BiomeJS.
npx @biomejs/biome check --apply . npx @biomejs/biome format --write . # Using bun bunx @biomejs/biome check --apply . bunx @biomejs/biome format --write .
- Building:
npm run build # Using bun bun run build
- Testing: (Basic setup exists)
npm test # Using bun bun test
To remove the globally linked command:
# Using npm
npm unlink -g gitmagic
# Using yarn
yarn global remove gitmagic
# Using pnpm
pnpm unlink -g gitmagic
# Using bun
bun unlink