Cheat sheets

The most needed commands and constructs on one page. Search by word, pick a language and copy a line with one click.

Cheat sheets

Git: daily commands

  • git initCreates a new repository in the current folder.
  • git clone <url>Copies a remote repository to your computer.
  • git statusShows modified, new and staged files.
  • git add .Stages all changes for the next commit.
  • git commit -m "message"Saves the staged changes with a short message.
  • git log --onelineShows the commit history, one line per commit.
  • git diffShows what changed in unstaged files.
  • git branchLists branches and marks the current one.
  • git switch -c featureCreates a new branch and switches to it.
  • git switch mainSwitches to another existing branch.
  • git merge featureMerges the feature branch into the current branch.
  • git pullFetches changes from the remote and merges them.
  • git push -u origin mainPushes commits to the server and remembers the branch.
  • git restore file.txtDiscards unsaved changes in a file.
  • git stashTemporarily shelves uncommitted changes.
  • git revert HEADCreates a commit that undoes the last commit.

Bash: essential commands

  • pwdPrints the full path of the current folder.
  • ls -laLists all files, including hidden ones, with details.
  • cd ~/projectsChanges to the given folder.
  • mkdir -p a/b/cCreates a folder along with any missing parents.
  • touch notes.txtCreates an empty file or updates its timestamp.
  • cp -r src backupCopies a folder with its contents.
  • mv old.txt new.txtRenames or moves a file.
  • rm -r buildDeletes a folder and its contents, no trash.
  • cat file.txtPrints the contents of a file.
  • grep -rn "todo" .Searches for text in files and shows line numbers.
  • find . -name "*.js"Finds files by name, starting from the current folder.
  • ls | wc -lPipes one command's output into another and counts lines.
  • echo "hi" > out.txtWrites output to a file, overwriting it.
  • echo "more" >> out.txtAppends output to the end of a file.
  • chmod +x run.shMakes a file executable.
  • export NAME=valueSets an environment variable for the current session.

Python: everyday syntax

  • print("Hello", name)Prints values to the screen.
  • name = input("Name: ")Reads a line typed by the user.
  • n = int("42")Converts a string to an integer.
  • f"{a} + {b} = {a + b}"A formatted string with expressions inside.
  • if x > 0: ... elif x == 0: ... else: ...Branches depending on a condition.
  • for i in range(5):Loops from 0 to 4.
  • while n > 0:Repeats a block while the condition is true.
  • def add(a, b): return a + bDefines a function that returns the sum.
  • nums = [1, 2, 3]Creates a list.
  • nums.append(4)Appends an item to the end of the list.
  • d = {"a": 1}Creates a dictionary of key-value pairs.
  • d.get("b", 0)Returns the value for a key or a default if missing.
  • [x * 2 for x in nums if x > 1]Builds a new list from another by a rule.
  • len(nums)Returns the number of items.
  • with open("a.txt") as f: text = f.read()Opens a file and always closes it afterwards.
  • try: ... except ValueError: ...Catches an error so the program does not crash.

JavaScript: basics

  • const x = 5;Declares a variable that cannot be reassigned.
  • let count = 0;Declares a variable whose value can change.
  • console.log(x);Prints a value to the console.
  • `Hi ${name}!`A template string with an embedded variable.
  • const add = (a, b) => a + b;An arrow function that returns the sum.
  • if (x === 1) { } else { }A condition using strict equality.
  • for (let i = 0; i < 5; i++) { }A classic counting loop.
  • const arr = [1, 2, 3];Creates an array.
  • arr.map((n) => n * 2)Returns a new array with transformed items.
  • arr.filter((n) => n > 1)Returns a new array with only the matching items.
  • const user = { name: "Ann", age: 20 };Creates an object with properties.
  • const { name } = user;Pulls an object property into a variable.
  • document.querySelector(".btn")Finds the first element matching a CSS selector.
  • btn.addEventListener("click", fn);Runs a function when an event happens.
  • const res = await fetch(url);Makes a network request inside an async function.
  • JSON.parse(text)Turns a JSON string into an object.

SQL: queries

  • SELECT * FROM users;Selects all columns and rows of a table.
  • SELECT name, age FROM users;Selects only the listed columns.
  • SELECT * FROM users WHERE age >= 18;Filters rows by a condition.
  • SELECT * FROM users ORDER BY age DESC;Sorts the result in descending order.
  • SELECT * FROM users LIMIT 10;Limits how many rows are returned.
  • SELECT DISTINCT city FROM users;Returns only unique values.
  • SELECT COUNT(*) FROM users;Counts the rows.
  • SELECT city, AVG(age) FROM users GROUP BY city;Groups rows and averages each group.
  • ... GROUP BY city HAVING COUNT(*) > 5;Filters groups after grouping.
  • SELECT * FROM users WHERE name LIKE 'A%';Matches text against a pattern.
  • INSERT INTO users (name, age) VALUES ('Ann', 20);Adds a new row to a table.
  • UPDATE users SET age = 21 WHERE id = 1;Changes values in the matching rows.
  • DELETE FROM users WHERE id = 1;Deletes the rows matching the condition.
  • SELECT o.id, u.name FROM orders o JOIN users u ON u.id = o.user_id;Joins two tables on a shared key.
  • CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);Creates a new table with columns.
  • DROP TABLE users;Permanently deletes a table with its data.

HTML: markup

  • <!DOCTYPE html>Tells the browser this is a modern HTML document.
  • <html lang="uk">The root element with the content language.
  • <meta charset="utf-8">Sets the encoding so text displays correctly.
  • <title>My page</title>The page title shown in the browser tab.
  • <h1>Heading</h1>The main page heading.
  • <p>Text</p>A paragraph of text.
  • <a href="https://example.com">Link</a>A link to another page.
  • <img src="cat.jpg" alt="Cat">An image with alternative text.
  • <ul><li>One</li><li>Two</li></ul>A bulleted list.
  • <ol><li>First</li></ol>A numbered list.
  • <div class="box"></div>A generic block for grouping elements.
  • <button type="button">Click</button>A clickable button.
  • <form action="/send" method="post">A form that sends data to a server.
  • <input type="text" name="q" required>A text field that cannot be left empty.
  • <label for="q">Search</label>A caption tied to an input field.
  • <link rel="stylesheet" href="style.css">Attaches a stylesheet file.

CSS: styling

  • p { color: #333; }Sets the text color for all paragraphs.
  • .card { background: white; }Styles elements with the card class.
  • #menu { margin: 0 auto; }Styles the element with id menu and centers it.
  • font: 16px/1.5 sans-serif;Font size, line height and family.
  • padding: 8px 16px;Inner spacing: vertical and horizontal.
  • margin-bottom: 1rem;Outer spacing below the element.
  • border: 1px solid #ccc;A thin solid border.
  • border-radius: 8px;Rounds the corners.
  • box-sizing: border-box;Includes padding and border in the total width.
  • display: flex;Turns on flexible layout for children.
  • justify-content: space-between;Spreads flex items along the main axis.
  • gap: 12px;Spacing between flex or grid items.
  • display: grid; grid-template-columns: repeat(3, 1fr);A grid with three equal columns.
  • a:hover { text-decoration: underline; }A style applied when the cursor hovers.
  • @media (max-width: 600px) { }Rules that apply only on narrow screens.
  • :root { --accent: #0a84ff; }Declares a CSS variable available everywhere.

Regular expressions

  • abcMatches the exact sequence of characters.
  • .Any single character except a newline.
  • \dA single digit.
  • \wA letter, digit or underscore.
  • \sA space, tab or line break.
  • [abc]One of the characters a, b or c.
  • [^0-9]Any character except digits.
  • ^startMatches only at the start of the line.
  • end$Matches only at the end of the line.
  • a*Zero or more repeats of a character.
  • a+One or more repeats of a character.
  • colou?rAn optional character: matches color and colour.
  • \d{3}Exactly three digits in a row.
  • (cat|dog)A group with a choice: cat or dog.
  • \bword\bA whole word, not part of a longer one.
  • .*?A lazy match: takes as few characters as possible.

More in the Study

A cheat sheet is not understanding

Lessons explain why a command works that way, and tasks let you apply it.