| name | git-version-control |
| description | Teaches Git/GitHub concepts and executes git commands. Invoke when users ask about version control, need help with git operations, or want to learn R4Psy Chapter 3.2 content. |
Git Version Control Skill
Overview
This skill helps users understand and use Git and GitHub based on the R4Psy course materials (Chapter 3.2). It combines educational content from slides/chapter_3.Rmd with practical command execution capabilities.
When to Invoke
- User asks about version control concepts (版本控制)
- User needs help with Git installation or configuration
- User wants to execute git commands (init, add, commit, push, pull, etc.)
- User needs guidance on GitHub operations (create repo, clone, fork, etc.)
- User encounters git errors or conflicts
- User references R4Psy Chapter 3 or asks about course content
Capabilities
1. Educational Content (Based on chapter_3.Rmd)
1.1 Version Control Concepts (3.2.1)
- Definition: 版本控制(Version Control)是一种管理文件修改历史的系统,特别是用于源代码管理。
- Categories:
- 本地版本控制 (Local): 在用户的个人计算机上运行,管理和跟踪文件或项目的历史版本
- 远程版本控制 (Remote): 侧重于团队协作和共享资源,依托于服务器或云服务
1.2 Git Fundamentals (3.2.2)
- Git is the most commonly used free and open-source version control tool
- Installation: https://git-scm.com/downloads
- Mac users may need to install homebrew first
Two Operation Modes:
- Terminal: Full functionality via Git Bash, CMD, R Terminal, etc.
- GUI Panel: Visual interface like R Studio Git panel, GitHub Desktop
1.3 GitHub Overview (3.2.3)
- GitHub is the world's largest open-source online software source code hosting platform
- Uses Git for version control
- Acquired by Microsoft in 2018
- Alternatives: Gitee, GitLab, Bitbucket
- Registration: https://github.com
2. Git Commands Reference
Initialization & Setup
git init
git clone <repository-url>
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --list
Daily Workflow
git status
git add <file>
git add .
git commit -m "Commit message"
git log
git log --oneline
git log --graph
Branch Operations
git branch
git branch <branch-name>
git checkout <branch-name>
git switch <branch-name>
git checkout -b <branch-name>
git switch -c <branch-name>
git merge <branch-name>
git branch -d <branch-name>
git branch -D <branch-name>
Remote Operations
git remote add origin <repository-url>
git remote -v
git push origin <branch-name>
git push -u origin <branch-name>
git pull origin <branch-name>
git fetch origin
git push --all origin
Undo Operations
git reset HEAD <file>
git restore --staged <file>
git checkout -- <file>
git restore <file>
git commit --amend
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
git stash
git stash list
git stash pop
git stash drop
3. GitHub Operations
Browser-based Operations
- Create Repository: User profile → Repositories → New
- Fork Repository: Click "Fork" button on any public repo
- Pull Requests: Compare & pull request → Create pull request
- Issues: Create and manage project issues
GitHub CLI Integration
gh auth login
gh repo create <repo-name>
gh repo clone <owner>/<repo>
gh pr create
gh issue list
4. Authentication Setup
SSH Key Setup
ssh-keygen -t ed25519 -C "your.email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Personal Access Token (PAT)
- GitHub → Settings → Developer settings → Personal access tokens
- Generate new token (classic) or Fine-grained token
- Select scopes: repo, workflow, etc.
- Use token as password when prompted
5. Error Handling
Common Issues & Solutions
Merge Conflicts:
git status
git add <resolved-files>
git commit -m "Resolve merge conflict"
Permission Denied:
- Check SSH key configuration
- Verify PAT has correct scopes
- Ensure correct repository access
Detached HEAD State:
git checkout -b <new-branch-name>
git checkout <branch-name>
Execution Guidelines
Teaching Mode
- When user asks about concepts, quote directly from chapter_3.Rmd (in Chinese)
- Provide context and examples to enhance understanding
- Reference specific sections (3.2.1, 3.2.2, 3.2.3) when applicable
Command Execution Mode
- Safety First: Always confirm before executing destructive commands (reset --hard, push --force, etc.)
- Explain Before Execute: Describe what the command does before running it
- Show Output: Display command output with explanations
- Check Status: Use
git status frequently to show current state
Interactive Guidance
- Assess Level: Ask about user's experience level if unclear
- Step-by-Step: Break complex operations into manageable steps
- Verify Understanding: Confirm user understands each step before proceeding
- Provide Alternatives: Offer both terminal and GUI options when applicable
Workflow Examples
First-time Setup
- Install Git
- Configure identity
- Set up SSH key or PAT
- Verify with
git --version and test connection
Starting a New Project
- Create GitHub repository (browser or gh CLI)
- Clone locally:
git clone <url>
- Add files and make initial commit
- Push to remote
Daily Development Loop
- Pull latest changes:
git pull
- Create feature branch:
git checkout -b feature-name
- Make changes and commit regularly
- Push branch:
git push -u origin feature-name
- Create pull request on GitHub
- Merge and clean up branches
Language Policy
- SKILL.md: English (this file)
- User Interaction: Chinese (consistent with chapter_3.Rmd source)
- Command Output: Preserve original language (English for git commands)
- Explanations: Chinese with English terms in parentheses when helpful
Safety Warnings
⚠️ Never:
- Execute
git push --force without explicit user confirmation
- Run
git reset --hard without checking for uncommitted changes
- Share or log authentication credentials
- Assume repository state without checking first
✅ Always:
- Check
git status before and after operations
- Confirm destructive actions
- Explain potential side effects
- Offer to create backups when appropriate