π¦ ClawHub
Doro Git Essentials
by @a2mus
Essential Git commands and workflows for version control, branching, and collaboration.
TERMINAL
clawhub install doro-git-essentialsπ About This Skill
name: doro-git-essentials description: Essential Git commands and workflows for version control, branching, and collaboration. version: 1.0.0 homepage: https://git-scm.com/ metadata: {"clawdbot":{"emoji":"π³","requires":{"bins":["git"]}}}
Git Essentials
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 initClone 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 statusAdd files to staging
git add file.txt
git add .
git add -A # All changes including deletionsCommit 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 diffShow staged changes
git diff --stagedShow changes in specific file
git diff file.txtShow changes between commits
git diff commit1 commit2
Branching & Merging
Branch management
# List branches
git branch
git branch -a # Include remote branchesCreate branch
git branch feature-nameSwitch branch
git checkout feature-name
git switch feature-name # Modern alternativeCreate and switch
git checkout -b feature-name
git switch -c feature-nameDelete branch
git branch -d branch-name
git branch -D branch-name # Force deleteRename branch
git branch -m old-name new-name
Merging
# Merge branch into current
git merge feature-nameMerge with no fast-forward
git merge --no-ff feature-nameAbort merge
git merge --abortShow merge conflicts
git diff --name-only --diff-filter=U
Remote Operations
Managing remotes
# List remotes
git remote -vAdd remote
git remote add origin https://github.com/user/repo.gitChange remote URL
git remote set-url origin https://github.com/user/new-repo.gitRemove remote
git remote remove origin
Syncing with remote
# Fetch from remote
git fetch originPull changes (fetch + merge)
git pullPull with rebase
git pull --rebasePush changes
git pushPush new branch
git push -u origin branch-nameForce push (careful!)
git push --force-with-lease
History & Logs
Viewing history
# Show commit history
git logOne line per commit
git log --onelineWith graph
git log --graph --oneline --allLast N commits
git log -5Commits 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.txtFind 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 wayDiscard all changes
git restore .
Staging area
# Unstage file
git restore --staged file.txt
git reset HEAD file.txt # Old wayUnstage all
git reset
Commits
# Undo last commit (keep changes)
git reset --soft HEAD~1Undo last commit (discard changes)
git reset --hard HEAD~1Revert commit (create new commit)
git revert commit-hashReset to specific commit
git reset --hard commit-hash
Stashing
# Stash changes
git stashStash with message
git stash save "Work in progress"List stashes
git stash listApply latest stash
git stash applyApply and remove stash
git stash popApply 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 mainInteractive rebase (last 3 commits)
git rebase -i HEAD~3Continue after resolving conflicts
git rebase --continueSkip current commit
git rebase --skipAbort rebase
git rebase --abort
Tags
# List tags
git tagCreate lightweight tag
git tag v1.0.0Create annotated tag
git tag -a v1.0.0 -m "Version 1.0.0"Tag specific commit
git tag v1.0.0 commit-hashPush tag
git push origin v1.0.0Push all tags
git push --tagsDelete 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-hashCherry-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 initUpdate submodules
git submodule updateClone with submodules
git clone --recursive https://github.com/user/repo.git
Clean
# Preview files to be deleted
git clean -nDelete untracked files
git clean -fDelete untracked files and directories
git clean -fdInclude 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
.gitignore for files to exclude--force-with-lease instead of --forceCommon 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/
π Tips & Best Practices
.gitignore for files to exclude--force-with-lease instead of --force