DEV Community

SEN LLC
SEN LLC

Posted on

A Git Cheatsheet With Fuzzy Search Over 82 Commands

A Git Cheatsheet With Fuzzy Search Over 82 Commands

Most Git cheatsheets are static pages you scroll through. This one has a fuzzy-matcher: type "staged" and you get git add, git diff --staged, git reset --soft in a single search. 82 commands organized into 10 categories, bilingual descriptions, one-click copy.

Git has hundreds of subcommands but most developers use about 20 on a daily basis. The problem is remembering the flags: was it --force or --force-with-lease? -d or -D? reset --hard or reset --soft? A searchable reference beats a static cheatsheet because you don't have to remember the exact command name.

๐Ÿ”— Live demo: https://sen.ltd/portfolio/git-cheatsheet/
๐Ÿ“ฆ GitHub: https://github.com/sen-ltd/git-cheatsheet

Screenshot

Features:

  • 82 Git commands in 10 categories
  • Fuzzy search across commands and descriptions
  • Bilingual Japanese / English
  • Daily workflow quick section (~15 most-used commands)
  • One-click copy
  • Terminal-themed dark UI
  • Zero dependencies, 29 tests

The fuzzy matcher

Classic fuzzy matching: every character of the query must appear in the target, in order, but not necessarily adjacent. The score rewards tight matches:

export function fuzzyMatch(query, text) {
  if (!query) return 1;
  const q = query.toLowerCase();
  const t = text.toLowerCase();
  let qi = 0;
  let score = 0;
  let lastMatchIdx = -1;
  for (let i = 0; i < t.length && qi < q.length; i++) {
    if (t[i] === q[qi]) {
      // Bonus if this match is adjacent to the previous
      if (lastMatchIdx === i - 1) score += 2;
      else score += 1;
      lastMatchIdx = i;
      qi++;
    }
  }
  return qi === q.length ? score : 0;
}
Enter fullscreen mode Exit fullscreen mode

Typing "staged" against "git diff --staged" scores higher than against "git reset --soft" because the letters are adjacent and in a shorter string.

Bilingual commands

Each command has descriptions in both languages:

{
  id: 'force-push',
  command: 'git push --force-with-lease',
  category: 'remote',
  tags: ['advanced'],
  description: {
    ja: 'ไป–ใฎไบบใฎๅค‰ๆ›ดใ‚’ไธŠๆ›ธใใ—ใชใ„ๅฎ‰ๅ…จใชๅผทๅˆถใƒ—ใƒƒใ‚ทใƒฅ',
    en: 'Safe force push that refuses to overwrite others\' work',
  },
},
Enter fullscreen mode Exit fullscreen mode

The search queries both language fields (respecting the current UI language) so Japanese users find commands by Japanese keywords, English users by English.

Categories

  • Setup (init, clone, config)
  • Staging & Commit (add, commit, commit --amend)
  • Branching (branch, checkout, switch)
  • Merging & Rebasing (merge, rebase -i, rebase --onto)
  • Remote (push, pull, fetch, push --force-with-lease)
  • Inspecting (log, diff, status, blame, reflog)
  • Undoing (reset, revert, restore, checkout -- file)
  • Stashing (stash, stash pop, stash apply)
  • Tags (tag, tag -a, tag -d)
  • Advanced (cherry-pick, bisect, worktree, clean -fd)

The "Daily" filter shows the ~15 commands developers use every session. Everything else is one search away.

Series

This is entry #47 in my 100+ public portfolio series.

Top comments (0)