| name | git-workflow-management |
| description | Automate frequent Git operations including adding changes, committing with meaningful messages, and pushing to remote repositories. Use when you need to save progress, commit code changes, or maintain regular version control workflow with proper commit practices. Use when this capability is needed. |
| metadata | {"author":"findinfinitelabs"} |
Git Workflow Management
Overview
A comprehensive skill for automating and streamlining Git version control operations, focusing on frequent commits with meaningful messages, proper staging practices, and efficient push workflows. Designed to maintain clean commit history and regular backup of development progress.
Capabilities
- Smart Change Detection: Automatically identify modified, added, and deleted files
- Intelligent Commit Messaging: Generate meaningful commit messages based on changes
- Selective Staging: Stage specific files or file types based on context
- Branch Management: Handle branch creation, switching, and merging workflows
- Push Automation: Automated pushing with conflict detection and resolution
- Commit History Cleanup: Squashing and organizing commits for clean history
Core Components
1. Automated Change Detection and Staging
#!/bin/bash
detect_changes() {
echo "🔍 Detecting changes..."
git status --porcelain | while read -r line; do
status="${line:0:2}"
file="${line:3}"
case "$status" in
"M "|" M") echo "Modified: $file" ;;
"A "|" A") echo "Added: $file" ;;
"D "|" D") echo "Deleted: $file" ;;
"??") echo "Untracked: $file" ;;
"R ") echo "Renamed: $file" ;;
esac
done
}
stage_by_type() {
local file_pattern="$1"
local description="$2"
if git diff --name-only --cached | grep -q "$file_pattern"; then
echo "✅ $description files already staged"
return 0
fi
if git diff --name-only | grep -q "$file_pattern"; then
echo "📁 Staging $description files..."
git add $(git diff --name-only | grep "$file_pattern")
return 0
fi
echo "ℹ️ No $description files to stage"
return 1
}
smart_staging() {
echo "🎯 Smart staging workflow..."
stage_by_type "\.py$" "Python"
stage_by_type "\.md$" "Markdown"
stage_by_type "\.js$\|\.ts$\|\.jsx$\|\.tsx$" "JavaScript/TypeScript"
stage_by_type "\.css$\|\.scss$\|\.sass$" "Stylesheet"
stage_by_type "\.html$\|\.htm$" "HTML"
stage_by_type "\.json$\|\.yml$\|\.yaml$" "Configuration"
stage_by_type "\.sql$" "Database"
stage_by_type "requirements\.txt\|package\.json\|Pipfile" "Dependencies"
echo "📋 Currently staged files:"
git diff --cached --name-only | sed 's/^/ ✓ /'
}
2. Intelligent Commit Message Generation
generate_commit_message() {
local commit_type="$1"
local scope="$2"
local description="$3"
local staged_files=$(git diff --cached --name-only)
local file_count=$(echo "$staged_files" | wc -l | xargs)
if [ -z "$description" ]; then
description=$(analyze_changes_for_message)
fi
if [ -n "$scope" ]; then
echo "${commit_type}(${scope}): ${description}"
else
echo "${commit_type}: ${description}"
fi
}
analyze_changes_for_message() {
local staged_files=$(git diff --cached --name-only)
local added_files=$(git diff --cached --name-status | grep '^A' | wc -l | xargs)
local modified_files=$(git diff --cached --name-status | grep '^M' | wc -l | xargs)
deleted_files=$(git diff --cached --name-status | grep | -l | xargs)
[ -gt 0 ] && [ -eq 0 ] && [ -eq 0 ];
| grep -q ;
| grep -q ;
[ -gt 0 ] && [ -eq 0 ] && [ -eq 0 ];
| grep -q ;
| grep -q ;
| grep -q ;
[ -gt 0 ];
}
() {
message_type=
scope=
custom_message=
[ -z ];
1
commit_message
[ -n ];
commit_message=
commit_message=$(generate_commit_message )
git diff --cached --name-only | sed
git commit -m
[ $? -eq 0 ];
0
1
}
3. Comprehensive Git Workflow Functions
import subprocess
import os
import sys
from datetime import datetime
from typing import List, Dict, Optional, Tuple
class GitWorkflowManager:
def __init__(self, repository_path: str = "."):
"""Initialize Git workflow manager."""
self.repo_path = repository_path
self.ensure_git_repository()
def ensure_git_repository(self):
"""Ensure we're in a Git repository."""
try:
subprocess.run(['git', 'rev-parse', '--git-dir'],
cwd=self.repo_path,
capture_output=True,
check=True)
except subprocess.CalledProcessError:
raise RuntimeError(f"Not a Git repository: {self.repo_path}")
def get_status(self) -> Dict[str, List[str]]:
"""Get comprehensive repository status."""
try:
result = subprocess.run(['git', 'status', ],
cwd=.repo_path,
capture_output=,
text=,
check=)
status = {
: [],
: [],
: [],
: [],
: [],
: []
}
line result.stdout.strip().split():
line:
status_code = line[:]
filename = line[:]
status_code[] [, , , , ]:
status[].append(filename)
status_code[] == :
status[].append(filename)
status_code[] == :
status[].append(filename)
status_code == :
status[].append(filename)
status_code[] == :
status[].append(filename)
status_code[] == :
status[].append(filename)
status
subprocess.CalledProcessError e:
RuntimeError()
() -> :
:
all_files:
subprocess.run([, , ], cwd=.repo_path, check=)
()
patterns:
pattern patterns:
subprocess.run([, , pattern], cwd=.repo_path, check=)
()
._interactive_staging()
subprocess.CalledProcessError e:
()
() -> :
status = .get_status()
(status.values()):
()
file_groups = {
: [f f status[] + status[] f.endswith()],
: [f f status[] + status[] f.endswith((, , ))],
: [f f status[] + status[] f.endswith((, , , ))],
: [f f status[] + status[] f.endswith((, , , ))],
: [f f status[] + status[] f.endswith((, , ))],
: []
}
all_categorized = ()
files file_groups.values():
all_categorized.update(files)
all_changes = (status[] + status[])
file_groups[] = (all_changes - all_categorized)
staged_any =
group_name, files file_groups.items():
files:
()
file files:
()
:
subprocess.run([, ] + files, cwd=.repo_path, check=)
()
staged_any =
subprocess.CalledProcessError:
()
staged_any
() -> :
:
result = subprocess.run([, , , ],
cwd=.repo_path,
capture_output=,
text=,
check=)
result.stdout.strip():
()
subprocess.CalledProcessError:
()
message auto_message:
message = ._generate_auto_commit_message(commit_type, scope)
message:
message =
:
subprocess.run([, , , message],
cwd=.repo_path,
check=)
()
subprocess.CalledProcessError e:
()
() -> :
:
result = subprocess.run([, , , ],
cwd=.repo_path,
capture_output=,
text=,
check=)
staged_files = result.stdout.strip().split()
file_analysis = {
: ([f f staged_files f.lower() f.endswith()]),
: ([f f staged_files f.endswith()]),
: ([f f staged_files f.endswith((, , ))]),
: ([f f staged_files f.endswith((, , , ))]),
: ([f f staged_files f.endswith((, , , ))]),
: ([f f staged_files f.endswith((, , ))])
}
file_analysis[] > :
description =
file_analysis[] > file_analysis[]:
description =
file_analysis[] > :
description =
file_analysis[] > :
description =
file_analysis[] > :
description =
file_analysis[] > :
description =
:
description =
scope:
:
subprocess.CalledProcessError:
() -> :
:
branch:
result = subprocess.run([, , ],
cwd=.repo_path,
capture_output=,
text=,
check=)
branch = result.stdout.strip()
:
subprocess.run([, , , , ],
cwd=.repo_path,
check=)
()
subprocess.CalledProcessError:
push_command = [, , remote, branch]
force:
push_command.append()
subprocess.run(push_command, cwd=.repo_path, check=)
()
subprocess.CalledProcessError e:
()
()
() -> :
()
stage_all:
.stage_files(all_files=):
:
.stage_files():
.commit_changes(message=message, commit_type=commit_type, scope=scope):
.push_changes():
()
() -> :
:
branch:
result = subprocess.run([, , ],
cwd=.repo_path,
capture_output=,
text=,
check=)
branch = result.stdout.strip()
()
subprocess.run([, , , remote, branch],
cwd=.repo_path,
check=)
()
subprocess.CalledProcessError e:
()
4. Command-Line Interface and Quick Commands
import argparse
import sys
def create_cli():
"""Create command-line interface for Git workflow management."""
parser = argparse.ArgumentParser(description="Git Workflow Management")
subparsers = parser.add_subparsers(dest='command', help='Available commands')
quick_parser = subparsers.add_parser('quick', help='Quick stage, commit, and push')
quick_parser.add_argument('-m', '--message', help='Custom commit message')
quick_parser.add_argument('-t', '--type', default='feat',
choices=['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore'],
help='Conventional commit type')
quick_parser.add_argument('-s', '--scope', help='Commit scope')
quick_parser.add_argument('--no-stage-all', action='store_true', help='Use interactive staging')
stage_parser = subparsers.add_parser('stage', help='Stage files')
stage_parser.add_argument('patterns', nargs='*', help='File patterns to stage')
stage_parser.add_argument(, , action=, =)
commit_parser = subparsers.add_parser(, =)
commit_parser.add_argument(, , =)
commit_parser.add_argument(, , default=, =)
commit_parser.add_argument(, , =)
push_parser = subparsers.add_parser(, =)
push_parser.add_argument(, , default=, =)
push_parser.add_argument(, , =)
push_parser.add_argument(, , action=, =)
status_parser = subparsers.add_parser(, =)
sync_parser = subparsers.add_parser(, =)
sync_parser.add_argument(, , default=, =)
sync_parser.add_argument(, , =)
parser
():
parser = create_cli()
args = parser.parse_args()
args.command:
parser.print_help()
sys.exit()
:
git_manager = GitWorkflowManager()
RuntimeError e:
()
sys.exit()
:
args.command == :
success = git_manager.quick_commit_and_push(
message=args.message,
commit_type=args.,
scope=args.scope,
stage_all= args.no_stage_all
)
args.command == :
success = git_manager.stage_files(
patterns=args.patterns,
all_files=args.
)
args.command == :
success = git_manager.commit_changes(
message=args.message,
commit_type=args.,
scope=args.scope
)
args.command == :
success = git_manager.push_changes(
remote=args.remote,
branch=args.branch,
force=args.force
)
args.command == :
status = git_manager.get_status()
print_status(status)
success =
args.command == :
success = git_manager.sync_with_remote(
remote=args.remote,
branch=args.branch
)
:
parser.print_help()
success =
sys.exit( success )
KeyboardInterrupt:
()
sys.exit()
Exception e:
()
sys.exit()
():
()
status[]:
()
file status[]:
()
status[]:
()
file status[]:
()
status[]:
()
file status[]:
()
status[]:
()
file status[]:
()
(status.values()):
()
__name__ == :
main()
Usage Examples
1. Quick Workflow (Most Common)
python git_workflow.py quick
python git_workflow.py quick -m "Add new Chuukese language processing features"
python git_workflow.py quick -t feat -s chuukese -m "Add accent normalization functionality"
2. Step-by-Step Workflow
python git_workflow.py status
python git_workflow.py stage *.py
python git_workflow.py stage -a
python git_workflow.py commit -t feat -s skills
python git_workflow.py push
3. Sync with Remote
python git_workflow.py sync
python git_workflow.py sync -r upstream -b main
Best Practices
1. Commit Message Conventions
- feat: New features or functionality
- fix: Bug fixes
- docs: Documentation changes
- style: Code style/formatting changes
- refactor: Code refactoring without feature changes
- test: Adding or updating tests
- chore: Maintenance tasks, dependency updates
2. Frequent Commit Guidelines
- Commit after completing logical units of work
- Keep commits focused on single concerns
- Use descriptive commit messages
- Commit before switching contexts or taking breaks
- Push regularly to backup work
3. File Organization
- Group related changes in single commits
- Separate feature development from documentation updates
- Commit configuration changes separately from code changes
- Keep dependency updates in dedicated commits
4. Workflow Automation
- Use quick commands for routine work
- Set up aliases for common operations
- Automate repetitive staging patterns
- Implement pre-commit hooks for quality checks
Integration with Development Tools
1. VS Code Integration
{
"version": "2.0.0",
"tasks": [
{
"label": "Quick Git Commit",
"type": "shell",
"command": "python",
"args": ["git_workflow.py", "quick"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
2. Shell Aliases
alias gq='python git_workflow.py quick'
alias gs='python git_workflow.py status'
alias gc='python git_workflow.py commit'
alias gp='python git_workflow.py push'
alias gsync='python git_workflow.py sync'
Dependencies
subprocess: Process execution for Git commands
argparse: Command-line interface
os: Operating system interface
datetime: Timestamp management
Validation Criteria
A successful implementation should:
- ✅ Automatically detect and stage relevant file changes
- ✅ Generate meaningful commit messages based on content
- ✅ Handle Git conflicts and errors gracefully
- ✅ Support both automated and interactive workflows
- ✅ Maintain clean commit history with conventional commits
- ✅ Provide clear status feedback throughout operations
- ✅ Support multiple remotes and branches
- ✅ Include comprehensive error handling and recovery
Converted and distributed by TomeVault — claim your Tome and manage your conversions.