{"skill":{"slug":"git-essentials","displayName":"Git Essentials","summary":"Essential Git commands and workflows for version control, branching, and collaboration.","description":"---\nname: git-essentials\ndescription: Essential Git commands and workflows for version control, branching, and collaboration.\nhomepage: https://git-scm.com/\nmetadata: {\"clawdbot\":{\"emoji\":\"🌳\",\"requires\":{\"bins\":[\"git\"]}}}\n---\n\n# Git Essentials\n\nEssential Git commands for version control and collaboration.\n\n## Initial Setup\n\n```bash\n# Configure user\ngit config --global user.name \"Your Name\"\ngit config --global user.email \"your@email.com\"\n\n# Initialize repository\ngit init\n\n# Clone repository\ngit clone https://github.com/user/repo.git\ngit clone https://github.com/user/repo.git custom-name\n```\n\n## Basic Workflow\n\n### Staging and committing\n```bash\n# Check status\ngit status\n\n# Add files to staging\ngit add file.txt\ngit add .\ngit add -A  # All changes including deletions\n\n# Commit changes\ngit commit -m \"Commit message\"\n\n# Add and commit in one step\ngit commit -am \"Message\"\n\n# Amend last commit\ngit commit --amend -m \"New message\"\ngit commit --amend --no-edit  # Keep message\n```\n\n### Viewing changes\n```bash\n# Show unstaged changes\ngit diff\n\n# Show staged changes\ngit diff --staged\n\n# Show changes in specific file\ngit diff file.txt\n\n# Show changes between commits\ngit diff commit1 commit2\n```\n\n## Branching & Merging\n\n### Branch management\n```bash\n# List branches\ngit branch\ngit branch -a  # Include remote branches\n\n# Create branch\ngit branch feature-name\n\n# Switch branch\ngit checkout feature-name\ngit switch feature-name  # Modern alternative\n\n# Create and switch\ngit checkout -b feature-name\ngit switch -c feature-name\n\n# Delete branch\ngit branch -d branch-name\ngit branch -D branch-name  # Force delete\n\n# Rename branch\ngit branch -m old-name new-name\n```\n\n### Merging\n```bash\n# Merge branch into current\ngit merge feature-name\n\n# Merge with no fast-forward\ngit merge --no-ff feature-name\n\n# Abort merge\ngit merge --abort\n\n# Show merge conflicts\ngit diff --name-only --diff-filter=U\n```\n\n## Remote Operations\n\n### Managing remotes\n```bash\n# List remotes\ngit remote -v\n\n# Add remote\ngit remote add origin https://github.com/user/repo.git\n\n# Change remote URL\ngit remote set-url origin https://github.com/user/new-repo.git\n\n# Remove remote\ngit remote remove origin\n```\n\n### Syncing with remote\n```bash\n# Fetch from remote\ngit fetch origin\n\n# Pull changes (fetch + merge)\ngit pull\n\n# Pull with rebase\ngit pull --rebase\n\n# Push changes\ngit push\n\n# Push new branch\ngit push -u origin branch-name\n\n# Force push (careful!)\ngit push --force-with-lease\n```\n\n## History & Logs\n\n### Viewing history\n```bash\n# Show commit history\ngit log\n\n# One line per commit\ngit log --oneline\n\n# With graph\ngit log --graph --oneline --all\n\n# Last N commits\ngit log -5\n\n# Commits by author\ngit log --author=\"Name\"\n\n# Commits in date range\ngit log --since=\"2 weeks ago\"\ngit log --until=\"2024-01-01\"\n\n# File history\ngit log -- file.txt\n```\n\n### Searching history\n```bash\n# Search commit messages\ngit log --grep=\"bug fix\"\n\n# Search code changes\ngit log -S \"function_name\"\n\n# Show who changed each line\ngit blame file.txt\n\n# Find commit that introduced bug\ngit bisect start\ngit bisect bad\ngit bisect good commit-hash\n```\n\n## Undoing Changes\n\n### Working directory\n```bash\n# Discard changes in file\ngit restore file.txt\ngit checkout -- file.txt  # Old way\n\n# Discard all changes\ngit restore .\n```\n\n### Staging area\n```bash\n# Unstage file\ngit restore --staged file.txt\ngit reset HEAD file.txt  # Old way\n\n# Unstage all\ngit reset\n```\n\n### Commits\n```bash\n# Undo last commit (keep changes)\ngit reset --soft HEAD~1\n\n# Undo last commit (discard changes)\ngit reset --hard HEAD~1\n\n# Revert commit (create new commit)\ngit revert commit-hash\n\n# Reset to specific commit\ngit reset --hard commit-hash\n```\n\n## Stashing\n\n```bash\n# Stash changes\ngit stash\n\n# Stash with message\ngit stash save \"Work in progress\"\n\n# List stashes\ngit stash list\n\n# Apply latest stash\ngit stash apply\n\n# Apply and remove stash\ngit stash pop\n\n# Apply specific stash\ngit stash apply stash@{2}\n\n# Delete stash\ngit stash drop stash@{0}\n\n# Clear all stashes\ngit stash clear\n```\n\n## Rebasing\n\n```bash\n# Rebase current branch\ngit rebase main\n\n# Interactive rebase (last 3 commits)\ngit rebase -i HEAD~3\n\n# Continue after resolving conflicts\ngit rebase --continue\n\n# Skip current commit\ngit rebase --skip\n\n# Abort rebase\ngit rebase --abort\n```\n\n## Tags\n\n```bash\n# List tags\ngit tag\n\n# Create lightweight tag\ngit tag v1.0.0\n\n# Create annotated tag\ngit tag -a v1.0.0 -m \"Version 1.0.0\"\n\n# Tag specific commit\ngit tag v1.0.0 commit-hash\n\n# Push tag\ngit push origin v1.0.0\n\n# Push all tags\ngit push --tags\n\n# Delete tag\ngit tag -d v1.0.0\ngit push origin --delete v1.0.0\n```\n\n## Advanced Operations\n\n### Cherry-pick\n```bash\n# Apply specific commit\ngit cherry-pick commit-hash\n\n# Cherry-pick without committing\ngit cherry-pick -n commit-hash\n```\n\n### Submodules\n```bash\n# Add submodule\ngit submodule add https://github.com/user/repo.git path/\n\n# Initialize submodules\ngit submodule init\n\n# Update submodules\ngit submodule update\n\n# Clone with submodules\ngit clone --recursive https://github.com/user/repo.git\n```\n\n### Clean\n```bash\n# Preview files to be deleted\ngit clean -n\n\n# Delete untracked files\ngit clean -f\n\n# Delete untracked files and directories\ngit clean -fd\n\n# Include ignored files\ngit clean -fdx\n```\n\n## Common Workflows\n\n**Feature branch workflow:**\n```bash\ngit checkout -b feature/new-feature\n# Make changes\ngit add .\ngit commit -m \"Add new feature\"\ngit push -u origin feature/new-feature\n# Create PR, then after merge:\ngit checkout main\ngit pull\ngit branch -d feature/new-feature\n```\n\n**Hotfix workflow:**\n```bash\ngit checkout main\ngit pull\ngit checkout -b hotfix/critical-bug\n# Fix bug\ngit commit -am \"Fix critical bug\"\ngit push -u origin hotfix/critical-bug\n# After merge:\ngit checkout main && git pull\n```\n\n**Syncing fork:**\n```bash\ngit remote add upstream https://github.com/original/repo.git\ngit fetch upstream\ngit checkout main\ngit merge upstream/main\ngit push origin main\n```\n\n## Useful Aliases\n\nAdd to `~/.gitconfig`:\n```ini\n[alias]\n    st = status\n    co = checkout\n    br = branch\n    ci = commit\n    unstage = reset HEAD --\n    last = log -1 HEAD\n    visual = log --graph --oneline --all\n    amend = commit --amend --no-edit\n```\n\n## Tips\n\n- Commit often, perfect later (interactive rebase)\n- Write meaningful commit messages\n- Use `.gitignore` for files to exclude\n- Never force push to shared branches\n- Pull before starting work\n- Use feature branches, not main\n- Rebase feature branches before merging\n- Use `--force-with-lease` instead of `--force`\n\n## Common Issues\n\n**Undo accidental commit:**\n```bash\ngit reset --soft HEAD~1\n```\n\n**Recover deleted branch:**\n```bash\ngit reflog\ngit checkout -b branch-name <commit-hash>\n```\n\n**Fix wrong commit message:**\n```bash\ngit commit --amend -m \"Correct message\"\n```\n\n**Resolve merge conflicts:**\n```bash\n# Edit files to resolve conflicts\ngit add resolved-files\ngit commit  # Or git merge --continue\n```\n\n## Documentation\n\nOfficial docs: https://git-scm.com/doc\nPro Git book: https://git-scm.com/book\nVisual Git guide: https://marklodato.github.io/visual-git-guide/\n","tags":{"latest":"1.0.0"},"stats":{"comments":1,"downloads":29761,"installsAllTime":284,"installsCurrent":284,"stars":36,"versions":1},"createdAt":1769692045864,"updatedAt":1778485868789},"latestVersion":{"version":"1.0.0","createdAt":1769692045864,"changelog":"Initial release of git-essentials.\n\n- Provides essential Git commands for setup, version control, branching, remote operations, stashing, rebasing, tagging, submodules, and cleaning.\n- Includes common workflows for feature branches, hotfixes, and syncing forks.\n- Offers helpful aliases, practical tips, and solutions to common issues.\n- Links to official Git documentation and resources for further learning.","license":null},"metadata":{"setup":[],"os":null,"systems":null},"owner":{"handle":"arnarsson","userId":"s1703vde870n8r5vvwnrs7xpg9884rg5","displayName":"Arnarsson","image":"https://avatars.githubusercontent.com/u/96142966?v=4"},"moderation":null}