Automatically configures Git with useful defaults and aliases for improved productivity and consistent development workflows.
Adds a setup-git function to configure Git with the following settings:
- 🔄 Enables Git rerere (reuse recorded resolution) for merge conflict handling
- 📊 Enables column output for better readability
- 📅 Sorts branches by last commit date
- 🔒 Safe defaults for push/pull behavior
- ⚡ Sets up useful aliases:
- logs: Pretty log with branch graph
- unstage: Unstages files
- p: Interactive patch mode
- undo: Undoes last commit
- fpush: Force push with lease
- publish: Pushes current branch with upstream setup
Import and run the setup function:
. .\git-config\git-config.ps1
setup-gitWhen using the PowerShell profile from this repository, setup-git runs automatically in the background during startup. A sentinel file (.git-config-done) is created after successful setup to avoid re-running on every startup.
- The configuration is re-verified automatically every 7 days
- To force immediate re-configuration:
setup-git -Force - To change the refresh interval, modify
$gitConfigRefreshDaysingit-config.ps1 - To manually trigger a refresh, delete
.git-config-donefrom the repository root
| Setting | Value | Description |
|---|---|---|
| rerere.enabled | true | Remembers merge conflict resolutions |
| column.ui | auto | Enables columnar output |
| branch.sort | -committerdate | Sorts branches by recent commits |
| logs | log --graph --pretty=... | Shows commit history with branch graph |
| unstage | reset HEAD -- | Removes files from staging area |
| p | add --patch | Interactively stage changes |
| undo | reset --soft HEAD~1 | Undoes last commit, preserving changes |
| fpush | push --force-with-lease | Safer force push |
| publish | !git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD) | Pushes current branch with upstream setup |
- Git 2.0+
- PowerShell 5.1+
- Ensure Git is installed and accessible from PowerShell
- Run PowerShell with administrator privileges if needed
- Check git config --list to verify settings
MIT © Scott Anderson 2024
For more utilities, visit the main repository here