mcpField
G
git-essentials

git-essentials

github.com/sundial-org開発670126 回インストール34 週間前に更新
リポジトリ

git-essentials について

git-essentialsは、一般的なGitコマンドと共同作業の手順をまとめたリファレンススキルです。開発者がリポジトリの変更、ブランチ、リモート、履歴や復旧を扱う際に役立ちます。

主な機能

  1. 01変更のステージング、コミット、確認
  2. 02ブランチとマージの管理
  3. 03リモートリポジトリとの同期
  4. 04履歴の検索とログの確認
  5. 05変更の取り消しと作業の復旧
  6. 06リベース、タグ、サブモジュールの利用

活用シーン

  1. 01一般的なGitコマンドの学習
  2. 02マージまでのフィーチャーブランチ管理
  3. 03フォークと上流リポジトリの同期
  4. 04誤ったコミットや削除からの復旧

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/sundial-org/awesome-openclaw-skills --skill git-essentials

インストール後、Claude Code で/git-essentialsを入力して読み込まれたか確認します。

詳細

Git の基本

バージョン管理と共同作業に役立つ必須の Git コマンドです。

初期設定

# Configure user
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

# Initialize repository
git init

# Clone repository
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git custom-name

基本的なワークフロー

ステージングとコミット
# Check status
git status

# Add files to staging
git add file.txt
git add .
git add -A  # All changes including deletions

# Commit changes
git commit -m "Commit message"

# Add and commit in one step
git commit -am "Message"

# Amend last commit
git commit --amend -m "New message"
git commit --amend --no-edit  # Keep message
変更の確認
# Show unstaged changes
git diff

# Show staged changes
git diff --staged

# Show changes in specific file
git diff file.txt

# Show changes between commits
git diff commit1 commit2

ブランチとマージ

ブランチの管理
# List branches
git branch
git branch -a  # Include remote branches

# Create branch
git branch feature-name

# Switch branch
git checkout feature-name
git switch feature-name  # Modern alternative

# Create and switch
git checkout -b feature-name
git switch -c feature-name

# Delete branch
git branch -d branch-name
git branch -D branch-name  # Force delete

# Rename branch
git branch -m old-name new-name
マージ
# Merge branch into current
git merge feature-name

# Merge with no fast-forward
git merge --no-ff feature-name

# Abort merge
git merge --abort

# Show merge conflicts
git diff --name-only --diff-filter=U

リモート操作

リモートの管理
# List remotes
git remote -v

# Add remote
git remote add origin https://github.com/user/repo.git

# Change remote URL
git remote set-url origin https://github.com/user/new-repo.git

# Remove remote
git remote remove origin
リモートとの同期
# Fetch from remote
git fetch origin

# Pull changes (fetch + merge)
git pull

# Pull with rebase
git pull --rebase

# Push changes
git push

# Push new branch
git push -u origin branch-name

# Force push (careful!)
git push --force-with-lease

履歴とログ

履歴の確認
# Show commit history
git log

# One line per commit
git log --oneline

# With graph
git log --graph --oneline --all

# Last N commits
git log -5

# Commits by author
git log --author="Name"

# Commits in date range
git log --since="2 weeks ago"
git log --until="2024-01-01"

# File history
git log -- file.txt
履歴の検索
# Search commit messages
git log --grep="bug fix"

# Search code changes
git log -S "function_name"

# Show who changed each line
git blame file.txt

# Find commit that introduced bug
git bisect start
git bisect bad
git bisect good commit-hash

変更の取り消し

作業ディレクトリ
# Discard changes in file
git restore file.txt
git checkout -- file.txt  # Old way

# Discard all changes
git restore .
ステージングエリア
# Unstage file
git restore --staged file.txt
git reset HEAD file.txt  # Old way

# Unstage all
git reset
コミット
# Undo last commit (keep changes)
git reset --soft HEAD~1

# Undo last commit (discard changes)
git reset --hard HEAD~1

# Revert commit (create new commit)
git revert commit-hash

# Reset to specific commit
git reset --hard commit-hash

スタッシュ

# Stash changes
git stash

# Stash with message
git stash save "Work in progress"

# List stashes
git stash list

# Apply latest stash
git stash apply

# Apply and remove stash
git stash pop

# Apply specific stash
git stash apply stash@{2}

# Delete stash
git stash drop stash@{0}

# Clear all stashes
git stash clear

リベース

# Rebase current branch
git rebase main

# Interactive rebase (last 3 commits)
git rebase -i HEAD~3

# Continue after resolving conflicts
git rebase --continue

# Skip current commit
git rebase --skip

# Abort rebase
git rebase --abort

タグ

# List tags
git tag

# Create lightweight tag
git tag v1.0.0

# Create annotated tag
git tag -a v1.0.0 -m "Version 1.0.0"

# Tag specific commit
git tag v1.0.0 commit-hash

# Push tag
git push origin v1.0.0

# Push all tags
git push --tags

# Delete tag
git tag -d v1.0.0
git push origin --delete v1.0.0

高度な操作

チェリーピック
# Apply specific commit
git cherry-pick commit-hash

# Cherry-pick without committing
git cherry-pick -n commit-hash
サブモジュール
# Add submodule
git submodule add https://github.com/user/repo.git path/

# Initialize submodules
git submodule init

# Update submodules
git submodule update

# Clone with submodules
git clone --recursive https://github.com/user/repo.git
クリーン
# Preview files to be deleted
git clean -n

# Delete untracked files
git clean -f

# Delete untracked files and directories
git clean -fd

# Include ignored files
git clean -fdx

よく使われるワークフロー

フィーチャーブランチのワークフロー:

git checkout -b feature/new-feature
# Make changes
git add .
git commit -m "Add new feature"
git push -u origin feature/new-feature
# Create PR, then after merge:
git checkout main
git pull
git branch -d feature/new-feature

ホットフィックスのワークフロー:

git checkout main
git pull
git checkout -b hotfix/critical-bug
# Fix bug
git commit -am "Fix critical bug"
git push -u origin hotfix/critical-bug
# After merge:
git checkout main && git pull

フォークの同期:

git remote add upstream https://github.com/original/repo.git
git fetch upstream
git checkout main
git merge upstream/main
git push origin main

便利なエイリアス

~/.gitconfig に追加します:

[alias]
    st = status
    co = checkout
    br = branch
    ci = commit
    unstage = reset HEAD --
    last = log -1 HEAD
    visual = log --graph --oneline --all
    amend = commit --amend --no-edit

ヒント

  • 頻繁にコミットし、後から仕上げます(インタラクティブリベース)
  • 意味のあるコミットメッセージを書きます
  • 除外するファイルには .gitignore を使用します
  • 共有ブランチに強制プッシュしないでください
  • 作業を始める前にプルします
  • main ではなく、フィーチャーブランチを使用します
  • マージする前にフィーチャーブランチをリベースします
  • --force の代わりに --force-with-lease を使用します

よくある問題

誤ってコミットした内容を取り消す:

git reset --soft HEAD~1

削除したブランチを復元する:

git reflog
git checkout -b branch-name <commit-hash>

間違ったコミットメッセージを修正する:

git commit --amend -m "Correct message"

マージコンフリクトを解決する:

# Edit files to resolve conflicts
git add resolved-files
git commit  # Or git merge --continue

ドキュメント

公式ドキュメント: https://git-scm.com/doc Pro Git の書籍: https://git-scm.com/book Git のビジュアルガイド: https://marklodato.github.io/visual-git-guide/

コメント