首页龙虾技能列表 › Git Essentials — Git核心操作

🌳 Git Essentials — Git核心操作

v1.0.0

Git 核心操作指南,提供常用 Git 命令和最佳实践。

29· 24,400·232 当前·241 累计·💬 1
by @arnarsson (Arnarsson)·MIT-0
下载技能包
License
MIT-0
最后更新
2026/2/26
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
high confidence
该技能是纯指令式的Git参考指南,与其所述目的一致,不请求凭证、安装或系统访问。
评估建议
此技能是纯咨询指南:它不请求凭证、无安装步骤、不访问您的系统。它内部连贯,安装风险低。在生产环境中依赖它之前:1) 确认指南与您的Git版本和工作流匹配;2) 遵循安全最佳实践,特别是关于仓库访问和身份验证;3) 寻求帮助时不要将敏感的仓库数据或凭证粘贴到代理中;4) 如果来源和可维护性对您很重要,考虑优先选择具有可识别来源或主页的技能。...
详细分析 ▾
用途与能力
The name/description (Git commands and workflows) matches the SKILL.md content. The SKILL.md metadata declares a dependency on the git binary (requires bins: ["git"]), which is appropriate for this purpose — note the registry metadata earlier listed no required binaries, so there is a minor inconsistency between the manifest and the in-file metadata.
指令范围
Instructions are limited to Git usage (config, clone, commit, branch, merge, push, reset, clean, etc.). They do modify user state (e.g., writing to ~/.gitconfig via git config --global) and include destructive operations (git reset --hard, git clean -fdx, force pushes), which are expected for a Git reference but can cause data loss if used carelessly.
安装机制
This is an instruction-only skill with no install spec and no code files, so nothing is downloaded or written to disk by the skill itself — lowest-risk install footprint.
凭证需求
The skill does not request environment variables or credentials, which is proportional. Note that interacting with remotes (clone/push/pull) will use whatever Git auth is available on the host (SSH keys, credential helpers, or interactive username/password), but the skill itself does not ask for or exfiltrate credentials.
持久化与权限
The skill does not request always:true and is user-invocable; it does not attempt to modify other skills or system-wide agent settings. Its runtime instructions change local Git state as expected for Git operations, but it does not gain elevated platform privileges.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.0.02026/1/29

初始版本

● 无害

安装命令 点击复制

官方npx clawhub@latest install git-essentials
镜像加速npx clawhub@latest install git-essentials --registry https://cn.clawhub-mirror.com

技能文档

Essential Git commands for version control and collaboration.

Initial Setup

# Configure user
git config --global user.name "Your Name"
git config --global user.email "your@email.com"

# Initialize repository git init

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

Basic Workflow

Staging and committing

# 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

Viewing changes

# 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

Branching & Merging

Branch management

# 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

Merging

# 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

Remote Operations

Managing remotes

# 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

Syncing with remote

# 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

History & Logs

Viewing history

# 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

Searching history

# 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

Undoing Changes

Working directory

# Discard changes in file
git restore file.txt
git checkout -- file.txt  # Old way

# Discard all changes git restore .

Staging area

# Unstage file
git restore --staged file.txt
git reset HEAD file.txt  # Old way

# Unstage all git reset

Commits

# 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

Stashing

# 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

Rebasing

# 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

Tags

# 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

Advanced Operations

Cherry-pick

# Apply specific commit
git cherry-pick commit-hash

# Cherry-pick without committing git cherry-pick -n commit-hash

Submodules

# 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

Clean

# 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

Common Workflows

Feature branch workflow:

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

Hotfix workflow:

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

Syncing fork:

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

Useful Aliases

Add to ~/.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

Tips

  • Commit often, perfect later (interactive rebase)
  • Write meaningful commit messages
  • Use .gitignore for files to exclude
  • Never force push to shared branches
  • Pull before starting work
  • Use feature branches, not main
  • Rebase feature branches before merging
  • Use --force-with-lease instead of --force

Common Issues

Undo accidental commit:

git reset --soft HEAD~1

Recover deleted branch:

git reflog
git checkout -b branch-name 

Fix wrong commit message:

git commit --amend -m "Correct message"

Resolve merge conflicts:

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

Documentation

Official docs: https://git-scm.com/doc Pro Git book: https://git-scm.com/book Visual Git guide: https://marklodato.github.io/visual-git-guide/

数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务