SuperAPI AI Directory

git-workflow-helper

Office & productivity

View repository

Updated 10-15 21:33

About this skill

Git Workflow Helper Skill

A skill that supports Git workflows.

Overview

Provides Git best practices, command generation, and troubleshooting.

Main Features

  • Workflow suggestions: GitFlow、GitHub Flow、Trunk-Based
  • Command generation: Safe commands for complex operations
  • Conflict resolution: Assistance with resolving merge conflicts
  • History cleanup: rebase、squash、cherry-pick
  • Troubleshooting: Resolving common problems
  • Hook generation: pre-commit, pre-push, etc.

Usage

以下の操作のGitコマンドを生成:
- ブランチを作成
- 変更をコミット
- リモートにプッシュ
- プルリクエスト作成の準備

Workflow Patterns

GitHub Flow

# 1. 最新のmainブランチを取得
git checkout main
git pull origin main

# 2. 機能ブランチを作成
git checkout -b feature/user-authentication

# 3. 変更を加えてコミット
git add .
git commit -m "Add user authentication"

# 4. リモートにプッシュ
git push -u origin feature/user-authentication

# 5. プルリクエストを作成(GitHubで)

# 6. レビュー後、mainにマージ
# 7. ブランチを削除
git branch -d feature/user-authentication

Git Flow

# develop ブランチから機能ブランチを作成
git checkout develop
git checkout -b feature/new-feature

# 完了後、developにマージ
git checkout develop
git merge --no-ff feature/new-feature

# リリースブランチ
git checkout -b release/1.2.0 develop

# リリース準備完了
git checkout main
git merge --no-ff release/1.2.0
git tag -a v1.2.0 -m "Release version 1.2.0"

Commonly used commands

Undoing changes

# ステージング取り消し
git reset HEAD <file>

# ローカル変更を破棄
git checkout -- <file>

# 直前のコミットを修正
git commit --amend

# コミットを取り消し(変更は保持)
git reset --soft HEAD~1

# コミットを完全に取り消し
git reset --hard HEAD~1

Branch operations

# ブランチ一覧
git branch -a

# リモートブランチを削除
git push origin --delete <branch-name>

# ローカルブランチを削除
git branch -d <branch-name>

# 強制削除
git branch -D <branch-name>

# ブランチ名変更
git branch -m <old-name> <new-name>

Conflict resolution

# マージ中にコンフリクト発生
git merge feature-branch

# コンフリクトを確認
git status

# ファイルを編集してコンフリクトマーカーを削除
# <<<<<<<, =======, >>>>>>> を解決

# 解決済みとしてマーク
git add <resolved-file>

# マージを完了
git commit

# マージを中止する場合
git merge --abort

History cleanup

# 直近3つのコミットをsquash
git rebase -i HEAD~3

# エディタで pick を squash に変更

# コミットメッセージを統合

# 強制プッシュ(注意!)
git push --force-with-lease

Stash

# 変更を一時保存
git stash

# メッセージ付き
git stash save "Work in progress on feature X"

# 一覧
git stash list

# 適用
git stash apply

# 適用して削除
git stash pop

# 削除
git stash drop stash@{0}

Troubleshooting

Problem: Committed to the wrong branch

# 1. 現在のブランチ名を確認
git branch

# 2. コミットを取り消し(変更は保持)
git reset --soft HEAD~1

# 3. 正しいブランチに切り替え
git checkout correct-branch

# 4. 再度コミット
git add .
git commit -m "Your commit message"

Problem: Committed sensitive information

# 最新コミットの場合
git reset --soft HEAD~1
# ファイルを修正
git add .
git commit -m "Fixed commit"

# 既にプッシュ済みの場合
# 1. ファイルを履歴から削除
git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch path/to/secret/file" \
  --prune-empty --tag-name-filter cat -- --all

# 2. 強制プッシュ
git push --force --all

Problem: Rebase failed

# リベース中止
git rebase --abort

# または続行
git rebase --continue

Pre-commit Hook

#!/bin/bash
# .git/hooks/pre-commit

# ESLint実行
npm run lint || exit 1

# テスト実行
npm test || exit 1

# 機密情報チェック
if git diff --cached | grep -i "password\|secret\|api[_-]key"; then
  echo "機密情報が含まれている可能性があります"
  exit 1
fi

exit 0

Version Information

  • Skill Version: 1.0.0
  • Last updated: 2025-01-22

Usage examples:

以下の操作のGitコマンドを教えて:
1. 新しいブランチを作成
2. 変更をコミット
3. mainブランチの最新を取り込む
4. コンフリクトを解決
5. プッシュ

Safe and accurate Git commands will be generated!