Custom Powershell Commands
Create a Custom Git Command
If you use Git often, it can be annoying to type the same sequence of commands every time you want to commit and push changes. A small custom command can make that process much faster. In this case, we’ll make a command called gitter that asks for a commit message, then runs git add, git commit, and git push for you.
Create the Script
The easiest way to do this on Windows is with PowerShell. Create a file called gitter.ps1 in a folder that you want to use for custom commands, such as C:\Scripts.
param(
[string]$message
)
if (-not $message) {
$message = Read-Host "Enter commit message"
}
git add .
git commit -am "$message"
git push
This script accepts a message if you pass one in, but if you just run gitter, it will prompt you for the commit message.
Add It to Your PATH
To make gitter available anywhere in Windows Terminal, put the script folder in your PATH. If you saved it in C:\Scripts, add that folder to your user PATH.
You can do this through the Environment Variables settings, or by running this in PowerShell:
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Scripts", "User")
After updating PATH, restart Windows Terminal so it picks up the change.
Allow PowerShell Scripts
Windows may block local scripts by default. If that happens, you can allow your own scripts to run with this command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
This setting is usually enough for personal use and still keeps downloaded scripts restricted unless they are signed.
Use the Command
Once everything is set up, you can open Windows Terminal in any Git repository and run:
gitter
Then type your commit message when prompted. The script will stage your changes, commit them, and push them to the remote repository.
Optional: Pass the Message Directly
If you prefer, you can also pass the commit message as an argument instead of typing it into a prompt:
gitter "Fixed login bug"
This gives you a little more flexibility, especially if you want to use the command in scripts or automation later.