UNPKG

clitutor

Version:

Interactive CLI learning tool for beginners

236 lines (223 loc) 9.91 kB
const chalk = require('chalk'); const boxen = require('boxen'); const green = chalk.hex('#00FF00'); const cyan = chalk.cyan; const yellow = chalk.yellow; const magenta = chalk.magenta; const blue = chalk.blue; const dim = chalk.dim; const bold = chalk.bold; const red = chalk.red; function showGitMemo() { console.clear(); console.log( boxen( green.bold('🔄 GIT COMMAND REFERENCE') + '\n' + dim('Your complete guide to Git commands'), { padding: 1, margin: 1, borderStyle: 'double', borderColor: 'green' } ) ); // Git Basics console.log( boxen( cyan.bold('🎯 GIT BASICS - Getting Started\n\n') + bold('Repository Setup:\n') + ' git init ' + dim('→ Initialize new repository\n') + ' git clone [url] ' + dim('→ Copy remote repository\n') + ' git config --list ' + dim('→ Show configuration\n\n') + bold('Status & Information:\n') + ' git status ' + dim('→ Check working tree status\n') + ' git log ' + dim('→ View commit history\n') + ' git log --oneline ' + dim('→ Compact history view\n') + ' git log --graph ' + dim('→ Visual branch history\n') + ' git show [commit] ' + dim('→ Show commit details\n\n') + bold('Basic Workflow:\n') + ' git add [file] ' + dim('→ Stage specific file\n') + ' git add . ' + dim('→ Stage all changes\n') + ' git add -p ' + dim('→ Stage interactively\n') + ' git commit -m "message" ' + dim('→ Create commit\n') + ' git commit --amend ' + dim('→ Modify last commit\n') + ' git diff ' + dim('→ Show unstaged changes\n') + ' git diff --staged ' + dim('→ Show staged changes\n') + ' git diff [branch1]..[branch2] ' + dim('→ Compare branches'), { padding: 1, margin: { top: 1 }, borderColor: 'cyan' } ) ); // Branching & Merging console.log( boxen( yellow.bold('🌳 BRANCHING & MERGING\n\n') + bold('Branch Management:\n') + ' git branch ' + dim('→ List branches\n') + ' git branch [name] ' + dim('→ Create branch\n') + ' git branch -d [name] ' + dim('→ Delete branch\n') + ' git branch -D [name] ' + dim('→ Force delete branch\n') + ' git branch -m [new-name] ' + dim('→ Rename current branch\n\n') + bold('Switching & Merging:\n') + ' git checkout [branch] ' + dim('→ Switch to branch\n') + ' git checkout -b [name] ' + dim('→ Create & switch branch\n') + ' git switch [branch] ' + dim('→ Switch branch (newer)\n') + ' git merge [branch] ' + dim('→ Merge branch into current\n') + ' git merge --abort ' + dim('→ Cancel merge\n') + ' git rebase [branch] ' + dim('→ Rebase onto branch\n') + ' git rebase -i HEAD~[n] ' + dim('→ Interactive rebase\n\n') + bold('Cherry-picking:\n') + ' git cherry-pick [commit] ' + dim('→ Copy specific commit\n') + ' git cherry-pick --abort ' + dim('→ Cancel cherry-pick'), { padding: 1, margin: { top: 1 }, borderColor: 'yellow' } ) ); // Remote Operations console.log( boxen( magenta.bold('🌐 REMOTE OPERATIONS\n\n') + bold('Remote Management:\n') + ' git remote -v ' + dim('→ List remote URLs\n') + ' git remote add [name] [url] ' + dim('→ Add remote\n') + ' git remote remove [name] ' + dim('→ Remove remote\n') + ' git remote rename [old] [new] ' + dim('→ Rename remote\n\n') + bold('Syncing:\n') + ' git fetch ' + dim('→ Download remote changes\n') + ' git fetch --all ' + dim('→ Fetch all remotes\n') + ' git pull ' + dim('→ Fetch & merge\n') + ' git pull --rebase ' + dim('→ Fetch & rebase\n') + ' git push ' + dim('→ Upload commits\n') + ' git push -u origin [branch] ' + dim('→ Push & set upstream\n') + ' git push --force ' + dim('→ Force push (careful!)\n') + ' git push --tags ' + dim('→ Push all tags\n\n') + bold('Pull Requests:\n') + ' git push origin [branch] ' + dim('→ Push for PR\n') + ' git fetch origin pull/[id]/head:[branch] ' + dim('→ Fetch PR'), { padding: 1, margin: { top: 1 }, borderColor: 'magenta' } ) ); // Stashing & Temporary Storage console.log( boxen( blue.bold('💾 STASHING & TEMPORARY STORAGE\n\n') + bold('Stash Operations:\n') + ' git stash ' + dim('→ Save current changes\n') + ' git stash save "message" ' + dim('→ Stash with description\n') + ' git stash list ' + dim('→ List all stashes\n') + ' git stash show ' + dim('→ Show stash contents\n') + ' git stash pop ' + dim('→ Apply & remove stash\n') + ' git stash apply ' + dim('→ Apply but keep stash\n') + ' git stash drop ' + dim('→ Delete latest stash\n') + ' git stash clear ' + dim('→ Delete all stashes\n') + ' git stash branch [name] ' + dim('→ Create branch from stash\n\n') + bold('Selective Stashing:\n') + ' git stash -p ' + dim('→ Stash interactively\n') + ' git stash --keep-index ' + dim('→ Stash only unstaged\n') + ' git stash --include-untracked ' + dim('→ Include new files'), { padding: 1, margin: { top: 1 }, borderColor: 'blue' } ) ); // Undoing & Recovery console.log( boxen( red.bold('⚡ UNDOING & RECOVERY\n\n') + bold('Undoing Changes:\n') + ' git restore [file] ' + dim('→ Discard file changes\n') + ' git restore --staged [file] ' + dim('→ Unstage file\n') + ' git reset HEAD~1 ' + dim('→ Undo last commit (keep changes)\n') + ' git reset --soft HEAD~1 ' + dim('→ Undo commit, keep staged\n') + ' git reset --hard HEAD~1 ' + dim('→ Undo commit & changes\n') + ' git reset --hard origin/[branch] ' + dim('→ Reset to remote\n') + ' git revert [commit] ' + dim('→ Create undo commit\n\n') + bold('Recovery & History:\n') + ' git reflog ' + dim('→ Show all ref updates\n') + ' git reflog show [branch] ' + dim('→ Branch reflog\n') + ' git fsck --lost-found ' + dim('→ Find dangling commits\n') + ' git bisect start ' + dim('→ Start binary search\n') + ' git bisect good/bad ' + dim('→ Mark commit state\n') + ' git blame [file] ' + dim('→ Show line authors'), { padding: 1, margin: { top: 1 }, borderColor: 'red' } ) ); // Advanced Git console.log( boxen( green.bold('🥷 ADVANCED GIT\n\n') + bold('Tags:\n') + ' git tag ' + dim('→ List tags\n') + ' git tag [name] ' + dim('→ Create lightweight tag\n') + ' git tag -a [name] -m "msg" ' + dim('→ Create annotated tag\n') + ' git push origin [tag] ' + dim('→ Push specific tag\n') + ' git tag -d [name] ' + dim('→ Delete local tag\n\n') + bold('Submodules:\n') + ' git submodule add [url] ' + dim('→ Add submodule\n') + ' git submodule update --init ' + dim('→ Initialize submodules\n') + ' git submodule update --recursive ' + dim('→ Update all\n\n') + bold('Useful Aliases:\n') + ' git config --global alias.co checkout\n' + ' git config --global alias.br branch\n' + ' git config --global alias.ci commit\n' + ' git config --global alias.st status\n' + ' git config --global alias.unstage "reset HEAD --"\n' + ' git config --global alias.last "log -1 HEAD"\n' + ' git config --global alias.visual "log --graph --oneline"', { padding: 1, margin: { top: 1 }, borderColor: 'green' } ) ); // Pro Tips console.log( boxen( green.bold('💡 GIT PRO TIPS\n\n') + '• Use ' + bold('.gitignore') + ' to exclude files from tracking\n' + '• Write clear, descriptive commit messages\n' + '• Commit often with logical, atomic changes\n' + '• Pull before push to avoid conflicts\n' + '• Use branches for features and experiments\n' + '• Review changes with ' + bold('git diff') + ' before committing\n' + '• Use ' + bold('git status') + ' frequently to stay oriented\n' + '• Learn to read ' + bold('git log --graph') + ' output\n' + '• Set up SSH keys for easier authentication\n' + '• Use ' + bold('git stash') + ' to temporarily save work\n' + '• Master ' + bold('git rebase -i') + ' for clean history\n' + '• Always backup before dangerous operations\n\n' + dim('Remember: Git is your safety net! 🦺'), { padding: 1, margin: { top: 1 }, borderColor: 'green', borderStyle: 'round' } ) ); console.log('\n' + dim('Exit with Ctrl+C or keep open for reference!\n')); // Handle graceful exit process.on('SIGINT', () => { console.log('\n' + green('Thanks for using clitutor git reference! 🚀\n')); process.exit(0); }); } module.exports = { showGitMemo };