GoIt is a command-line tool developed in Go for efficient Git branch management, focusing on helping developers manage local Git branches effectively.
Features
- 🔍 Smart Branch Query - Filter branches based on commit time
- 🗑️ Batch Branch Deletion - Safely delete expired branches
- ⏰ Flexible Time Format - Support for minutes(m), hours(h), days(d) time units
- 🛡️ Branch Protection - Automatically protect main branches (main, master, develop)
- 📊 Detailed Information Display - Show branch commit time, author, and other information
Installation
Build from Source
git clone https://github.com/aitechwizard/goit.git
cd goit
go build -o bin/goit ./cmd/goit
Using Go Install
go install github.com/aitechwizard/goit/cmd/goit@latest
Usage
Basic Syntax
goit branch [options]
# or use alias
goit br [options]
Options
| Option |
Alias |
Description |
Example |
--time |
-t |
Specify time range, supports m(minutes), h(hours), d(days) |
-t 7d, -t 2h, -t 30m |
--reverse |
-r |
Reverse time condition (find branches older than specified time) |
-r |
--list |
-l |
List branches matching criteria |
-l |
--delete |
-d |
Delete branches matching criteria |
-d |
Examples
1. List Branches
# List branches with latest commit newer than 7 days ago
goit br -l -t 7d
# List branches with latest commit older than 30 days ago (using reverse condition)
goit br -l -r -t 30d
# List branches with latest commit newer than 2 hours ago
goit br -l -t 2h
2. Delete Branches
# Delete branches with latest commit older than 30 days ago
goit br -d -r -t 30d
# Delete branches with latest commit older than 7 days ago
goit br -d -r -t 7d
# Delete branches with latest commit newer than 1 hour ago
goit br -d -t 1h
Supported time units:
m - Minutes (e.g., 30m = 30 minutes)
h - Hours (e.g., 2h = 2 hours)
d - Days (e.g., 7d = 7 days)
Branch Protection
The following branches are automatically protected and will not be deleted:
- Current branch
main branch
master branch
develop branch
Output Examples
List Branches Example
查找最新提交时间早于 2024-01-15 10:30:00 的分支:
----------------------------------------
找到 3 个符合条件的分支:
分支: feature/old-feature
最新提交时间: 2024-01-10 14:20:15
作者: John Doe
分支: bugfix/legacy-fix
最新提交时间: 2024-01-08 09:15:30
作者: Jane Smith
分支: experiment/test-branch
最新提交时间: 2024-01-05 16:45:22
作者: Bob Wilson
Delete Branches Example
准备删除最新提交时间早于 2024-01-15 10:30:00 的分支:
----------------------------------------
已删除分支: feature/old-feature (最新提交: 2024-01-10 14:20:15)
已删除分支: bugfix/legacy-fix (最新提交: 2024-01-08 09:15:30)
跳过的保护分支: [main, develop]
总共删除了 2 个分支
Common Use Cases
1. Clean Up Expired Feature Branches
# Delete old branches from 30 days ago
goit br -d -r -t 30d
2. View Recently Active Branches
# View branches with commits in the last 7 days
goit br -l -t 7d
3. Clean Up Short-term Experimental Branches
# Delete experimental branches from 1 day ago
goit br -d -r -t 1d
Technical Implementation
Contributing
Issues and Pull Requests are welcome!
License
MIT License
Changelog
v1.0.0
- Initial release
- Support for time-based branch querying and deletion
- Support for branch protection mechanism
- Support for flexible time formats
Requirements
- Go 1.23 or later
- Git repository (the tool must be run within a Git repository)
Troubleshooting
Common Issues
-
"未找到Git仓库" (Git repository not found)
- Make sure you're running the command within a Git repository
- Check if the
.git directory exists in your current directory or parent directories
-
Permission denied when deleting branches
- Ensure you have write permissions to the Git repository
- Make sure the branches you're trying to delete are not currently checked out
-
Time format errors
- Use only supported time units:
m (minutes), h (hours), d (days)
- Ensure the number is positive (e.g.,
5d, not 0d or -5d)
Development
Building
# Build for current platform
go build -o bin/goit ./cmd/goit
# Build for multiple platforms
make build-all
Testing
# Run tests
go test ./...
# Run tests with coverage
go test -cover ./...