Cheatsheets
One-page references for the commands and syntax you use every day.
Git
Everyday version control.
| Command | What it does |
|---|---|
git clone <url> | Copy a remote repository to your machine |
git status | See changed, staged and untracked files |
git add <file> | Stage a file (use `.` for everything) |
git commit -m "message" | Record the staged changes |
git log --oneline --graph | Compact history with branches |
git diff | Show unstaged changes |
git switch -c <branch> | Create and move to a new branch |
git merge <branch> | Merge a branch into the current one |
git pull | Fetch and integrate remote changes |
git push -u origin <branch> | Publish a branch and set its upstream |
git restore <file> | Discard unstaged changes to a file |
git stash | Shelve uncommitted work temporarily (`git stash pop` to bring it back) |
Linux shell
Navigating and working with files.
| Command | What it does |
|---|---|
pwd | Print the current directory |
ls -la | List files, including hidden ones, with details |
cd <dir> | Change directory (`cd ..` goes up, `cd` goes home) |
mkdir -p a/b | Create a directory and any missing parents |
cp -r <src> <dst> | Copy files or directories |
mv <src> <dst> | Move or rename |
rm -r <dir> | Delete a directory and its contents (no undo) |
cat <file> | Print a file |
grep -rn "text" . | Search for text in files, with line numbers |
chmod +x <file> | Make a file executable |
sudo apt install <pkg> | Install a package on Ubuntu/Debian |
ssh user@host | Log in to a remote machine |
SQL (PostgreSQL)
Querying a database.
| Command | What it does |
|---|---|
SELECT col1, col2 FROM t; | Pick columns from a table |
WHERE price > 10 AND active | Filter rows |
ORDER BY created_at DESC | Sort results |
LIMIT 10 OFFSET 20 | Page through results |
SELECT DISTINCT col FROM t; | Remove duplicate values |
GROUP BY col | Aggregate per group (with COUNT, SUM, AVG, MIN, MAX) |
HAVING COUNT(*) > 5 | Filter groups after aggregation |
JOIN b ON a.id = b.a_id | Combine tables (LEFT JOIN keeps unmatched rows of a) |
INSERT INTO t (a, b) VALUES (1, 2); | Add a row |
UPDATE t SET a = 1 WHERE id = 5; | Change rows (always use WHERE) |
DELETE FROM t WHERE id = 5; | Remove rows (always use WHERE) |
\dt · \d table · \q | psql: list tables, describe a table, quit |
Python · pandas
Working with tabular data.
| Command | What it does |
|---|---|
df = pd.read_csv("file.csv") | Load a CSV file |
df.head() · df.info() | Peek at rows and column types |
df.describe() | Summary statistics for numeric columns |
df["col"] · df[["a", "b"]] | Select one column or several |
df[df["age"] > 18] | Filter rows by a condition |
df.loc[row, col] · df.iloc[i, j] | Select by label or by position |
df.isna().sum() | Count missing values per column |
df.dropna() · df.fillna(0) | Drop or fill missing values |
df.groupby("k")["v"].mean() | Aggregate per group |
df.sort_values("col", ascending=False) | Sort rows |
pd.merge(a, b, on="id", how="left") | Join two DataFrames |
df.to_csv("out.csv", index=False) | Save to CSV |
LaTeX
Papers and theses.
| Command | What it does |
|---|---|
\section{Title} · \subsection{Title} | Headings |
\textbf{bold} · \emph{italic} | Emphasis |
$x^2 + y_i$ | Inline math |
\[ \sum_{i=1}^{n} x_i \] | Displayed math |
\begin{itemize} \item … \end{itemize} | Bulleted list (`enumerate` for numbered) |
\includegraphics[width=0.8\linewidth]{fig.png} | Insert an image (needs `graphicx`) |
\label{fig:a} · \ref{fig:a} | Name something and refer to it |
\cite{key} | Cite an entry from your .bib file |