Git Bash Cheat Sheet
A Bash shell for Windows, installed with Git for Windows. You get Linux commands (ls, grep, ssh…) on your Windows files. For Git commands, see the Git cheat sheet.
On this page
Windows ↔ Git Bash Paths #
| Windows | Git Bash |
|---|---|
C:\Users\milan | /c/Users/milan or ~ |
D:\Projects | /d/Projects |
\ (backslash) | / (forward slash) |
%USERPROFILE% | $HOME |
Everyday Commands #
| Command | Action |
|---|---|
| Show the current folder | |
| List files and folders ( = all files, with details) | |
| / | Home folder / previous folder |
| Create nested folders | |
| Create an empty file | |
| Copy a folder | |
| Move / rename | |
| Delete a folder (no Recycle Bin!) | |
| / | View a file |
| / | First lines / follow a log |
| Search text recursively | |
| Find files | |
| Count lines | |
| Where a program is located | |
or Ctrl + L | Clear the screen |
Windows Integration #
| Command | Action |
|---|---|
| or | Open the current folder in Explorer |
| Open a URL in the browser | |
| Open a file in Notepad | |
| Open the folder in VS Code | |
| Copy file content to the Windows clipboard | |
| Run interactive Windows programs correctly (python, node REPL) | |
| Run a cmd command |
Copy & Paste (mintty window) #
| Key | Action |
|---|---|
| Select text | Copies automatically |
Shift + Insert | Paste |
Ctrl + Insert | Copy |
| Right-click | Context menu (or paste, depending on options) |
Alt + Enter | Full screen |
Keyboard (Bash) #
| Key | Action |
|---|---|
Tab | Autocomplete |
Ctrl + R | Search command history |
Ctrl + A / Ctrl + E | Start / end of line |
Ctrl + U / Ctrl + K | Delete before / after the cursor |
Ctrl + W | Delete the previous word |
Ctrl + C | Stop the command |
!! | Repeat the last command |
SSH Keys (for GitHub etc.) #
ssh-keygen -t ed25519 -C "you@example.com" # create a key
eval "$(ssh-agent -s)" # start the agent
ssh-add ~/.ssh/id_ed25519 # load the key
cat ~/.ssh/id_ed25519.pub | clip # copy the public key → paste it on GitHub
ssh -T git@github.com # test
Config Files #
| File | Use |
|---|---|
~/.bashrc | Aliases and functions (loaded for every shell) |
~/.bash_profile | Login shell; usually just |
~/.gitconfig | Git settings |
~/.minttyrc | Window font and colors |
# ~/.bashrc examples
alias ll='ls -la'
alias gs='git status'
alias proj='cd /c/Repositories'
Reload with source ~/.bashrc.
Tips #
- If a path like
/c/...gets mangled when passed to a Windows program, prefix the command withMSYS_NO_PATHCONV=1. - Line endings:
git config --global core.autocrlf trueon Windows prevents CRLF/LF diffs. - Use Git Bash inside Windows Terminal or the VS Code terminal for tabs and better fonts.
echoPrint text. echo [options] text…
| Option | What it does |
|---|---|
-n | No newline at the end |
-e | Interpret escapes: \n newline, \t tab |
-E | Don't interpret escapes (default) |
echo $HOME | Print a variable |
echo "text" > file | Write to a file (>> appends) |
echo $? | Exit code of the last command |
pwdPrint the current folder. pwd [-L | -P]
| Option | What it does |
|---|---|
-L | Logical path, keeps symbolic links (default) |
-P | Physical path, symbolic links resolved |
Git Bash tip: pwd -W prints the Windows-style path (C:/Users/…).
lsList the files and folders in a directory. ls [options] [path…]
| Option | What it does |
|---|---|
-l | Long list: permissions, owner, size, date |
-a, --all | Also show hidden files (names starting with .) |
-A, --almost-all | Hidden files too, but without . and .. |
-h, --human-readable | Sizes like 4.0K, 12M, 1.1G (use with -l) |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-X | Sort by file extension |
-v | Natural sort of numbers (file2 before file10) |
-r, --reverse | Reverse the sort order |
-R, --recursive | List all subfolders too |
-d | List the folder itself, not what's inside (ls -d */ = only folders) |
-1 | One name per line |
-F, --classify | Add / after folders, * after executables, @ after links |
-i | Show inode numbers |
-n | Numeric user and group IDs |
-s | Show the allocated size of each file |
--color=auto | Colour output (always / never) |
--group-directories-first | Folders before files |
--time-style=long-iso | Dates as 2026-10-01 14:05 |
--sort=WORD | Sort by size, time, extension, version or none |
Popular combinations: ls -la (everything, detailed) · ls -lah (+ readable sizes) · ls -lt (newest first) · ls -lS (biggest first).
macOS: -G enables colour; the long --options don't exist there. Full list: man ls or ls --help.
cdChange the current folder. cd [path]
| Usage | What it does |
|---|---|
cd folder | Go into a folder (relative to where you are) |
cd /var/log | Go to an absolute path |
cd .. | One folder up (cd ../.. = two up) |
cd or cd ~ | Your home folder |
cd - | Back to the previous folder |
cd / | The root of the filesystem |
cd "My Folder" | Paths with spaces need quotes (or My\ Folder) |
-P | Resolve symbolic links to the real path |
-L | Follow symbolic links as they are (default) |
Git Bash: drives are /c/, /d/… WSL: Windows drives are under /mnt/c/.
mkdirCreate folders. mkdir [options] folder…
| Option | What it does |
|---|---|
-p, --parents | Create parent folders as needed; no error if it exists |
-v, --verbose | Print every folder created |
-m 755 | Set permissions while creating |
mkdir -p src/{components,pages,utils} | Several subfolders in one go |
touchCreate an empty file, or update a file's timestamp. touch [options] file…
| Option | What it does |
|---|---|
touch a.txt b.txt | Create several files at once |
touch file{1..5}.txt | Create file1.txt … file5.txt (brace expansion) |
-c, --no-create | Don't create the file if it doesn't exist |
-a | Change only the access time |
-m | Change only the modification time |
-d "2026-01-01 12:00" | Set a specific date/time |
-t 202601011200 | Set the time as [[CC]YY]MMDDhhmm[.ss] |
-r other.txt | Copy the timestamp from another file |
cpCopy files and folders. cp [options] source… destination
| Option | What it does |
|---|---|
-r, -R | Copy folders with everything inside |
-a, --archive | Recursive + keep permissions, owners, timestamps, links (best for backups) |
-i | Ask before overwriting |
-n | Never overwrite existing files |
-f | Force: delete a destination file that can't be opened, then copy |
-u | Only copy when the source is newer |
-v | Show every file copied |
-p | Keep mode, owner and timestamps |
-l | Make hard links instead of copies |
-s | Make symbolic links instead of copies |
-L | Follow symbolic links (copy what they point to) |
-t folder | Destination folder first: cp -t backup/ *.txt |
--backup | Keep a backup (file~) of files that would be overwritten |
Watch out: cp -r src dst creates dst/src when dst already exists (even with src/; unlike rsync, a trailing slash doesn't change this).
mvMove or rename files and folders. mv [options] source… destination
| Option | What it does |
|---|---|
-i | Ask before overwriting |
-n | Never overwrite |
-f | Overwrite without asking (default) |
-u | Only move when the source is newer |
-v | Show what is moved |
-b | Back up files that would be overwritten |
-t folder | Destination first: mv -t archive/ *.log |
-T | Treat the destination as a file, never as a folder |
Renaming is just moving: mv old.txt new.txt.
rmDelete files and folders. There is no recycle bin. rm [options] file…
| Option | What it does |
|---|---|
-r, -R | Delete folders and everything in them |
-f | Force: no questions, no error if the file is missing |
-i | Ask before every file |
-I | Ask once (when deleting more than 3 files or recursively) |
-v | Show what is deleted |
-d | Delete empty folders |
--preserve-root | Refuse to delete / (on by default) |
--one-file-system | Don't cross into other mounted drives |
⚠ Double-check before rm -rf. Test the pattern first with ls: ls *.tmp → rm *.tmp.
catPrint files (or join them). cat [options] file…
| Option | What it does |
|---|---|
-n | Number every line |
-b | Number non-empty lines only |
-s | Squeeze multiple empty lines into one |
-A | Show invisible characters: tabs as ^I, line ends as $ |
-E | Show $ at every line end (spot trailing spaces) |
-T | Show tabs as ^I |
cat a b > ab | Join files into a new one |
cat >> notes.txt | Type text and append it (end with Ctrl + D) |
lessScroll through a file or long output. less [options] file or command | less
| Option / key | What it does |
|---|---|
-N | Show line numbers |
-S | Don't wrap long lines (scroll sideways) |
-R | Show colours (git log | less -R) |
-i | Case-insensitive search |
+F | Follow the end of the file, like tail -f |
-X | Leave the content on screen after quitting |
Space / b | Page down / up |
g / G | Start / end of the file |
/text / ?text | Search forward / backward (n / N = next / previous) |
F | Start following (stop with Ctrl + C) |
q | Quit |
headShow the first lines of a file. head [options] file…
| Option | What it does |
|---|---|
-n 20 | First 20 lines (default 10) |
-n -5 | Everything except the last 5 lines |
-c 100 | First 100 bytes |
-q | Don't print file names when showing several files |
-v | Always print the file name |
tailShow the last lines of a file, or follow it live. tail [options] file…
| Option | What it does |
|---|---|
-n 50 | Last 50 lines (default 10) |
-n +100 | Everything from line 100 on |
-f | Follow: keep printing new lines (logs) |
-F | Follow and survive log rotation / file recreated |
-c 200 | Last 200 bytes |
--pid=1234 | Stop following when that process ends |
-s 5 | Check for new lines every 5 seconds (with -f) |
-q | No file-name headers |
Example: tail -f /var/log/syslog | grep error
grepSearch for text in files or command output. grep [options] pattern [file…]
| Option | What it does |
|---|---|
-i | Ignore upper/lower case |
-r | Search all files in folders (recursive) |
-R | Recursive and follow symbolic links |
-n | Show line numbers |
-v | Show lines that do not match |
-w | Match whole words only |
-x | Match whole lines only |
-c | Count matching lines per file |
-l | Only list the names of matching files |
-L | Only list files without a match |
-o | Print only the matching part |
-E | Extended regex (+, ?, |, () without backslashes) |
-F | Plain text, no regex (fast, safe for special characters) |
-P | Perl regex (\d, lookarounds) |
-A 3 / -B 3 / -C 3 | 3 lines After / Before / around each match |
-e pattern | Several patterns: -e foo -e bar |
--include="*.js" | Only search matching files (with -r) |
--exclude-dir=node_modules | Skip folders (with -r) |
-h / -H | Hide / show file names |
-q | Quiet: only the exit code (for scripts) |
-s | Hide "permission denied" style errors |
--color=auto | Highlight matches |
Example: grep -rni --include="*.ts" "todo" src/
findSearch for files by name, type, size, date… find [path] [tests] [actions]
| Option | What it does |
|---|---|
-name "*.js" | Name matches (case-sensitive, quote the pattern) |
-iname "*.jpg" | Name matches, case-insensitive |
-type f / -type d / -type l | Files / folders / symbolic links |
-size +100M / -size -1024c | Bigger than 100 MB / smaller than 1 KB (-1k only finds empty files) |
-mtime -1 / -mtime +30 | Changed in the last day / more than 30 days ago |
-mmin -15 | Changed in the last 15 minutes |
-newer ref.txt | Changed after ref.txt |
-maxdepth 2 / -mindepth 1 | Limit how deep to search |
-path "*/src/*" | Match on the whole path |
-empty | Empty files or folders |
-user milan / -perm 644 | Owned by / with these permissions |
-not -name …, ! | Negate a test |
-o | OR between tests: \( -name "*.jpg" -o -name "*.png" \) |
-exec cmd {} \; | Run a command for every match |
-exec cmd {} + | Run the command once with all matches (faster) |
-delete | Delete the matches (put it last!) |
-print0 | Null-separated output for xargs -0 |
-ls | ls -l style output |
Example: find . -name "node_modules" -type d -prune -o -name "*.ts" -print
wcCount lines, words and bytes. wc [options] file…
| Option | What it does |
|---|---|
-l | Lines |
-w | Words |
-c | Bytes |
-m | Characters (differs from bytes for UTF-8) |
-L | Length of the longest line |
Example: ls | wc -l counts the items in a folder.
whichalso: typeShow where a command comes from. which [-a] command
| Option | What it does |
|---|---|
which node | Path of the program that runs |
-a | All matches in PATH, not just the first |
type ll | (Bash built-in) also shows aliases, functions and built-ins |
type -a python | Every definition of the name |
command -v git | Portable way, handy in scripts |
clearClear the terminal screen. Shortcut: Ctrl + L.
| Option | What it does |
|---|---|
-x | Don't clear the scrollback (only the visible screen) |
reset | (separate command) fully reset a garbled terminal |
explorerOpen File Explorer. explorer [folder | /select,file | shell:folder]
| Usage | What it does |
|---|---|
explorer . | Open the current folder |
explorer /select,"C:\path\file.txt" | Open the folder and select the file |
explorer shell:startup | Special folders: shell:downloads, shell:appsfolder, shell:sendto |
explorer https://example.com | Open a URL in the default browser |
explorer.exe . | From WSL: open the Linux folder in Explorer |
startOpen a file, folder, URL or program in its own window (cmd built-in; also works in Git Bash). start ["title"] [options] target
| Option | What it does |
|---|---|
start . | Open the current folder in Explorer |
start https://github.com | Open a URL |
start file.pdf | Open with the default app |
start "" "C:\Program Files\App\app.exe" | Empty title first when the path has quotes |
/d C:\dev | Start folder |
/wait | Wait until the program closes |
/min / /max | Start minimized / maximized |
/b | Run in the same window without a new console |
notepadOpen Notepad. notepad [file]
| Usage | What it does |
|---|---|
notepad file.txt | Open (or create) a file |
notepad | Empty Notepad |
notepad /p file.txt | Print the file |
From WSL use notepad.exe file.txt.
codeVS Code from the command line. code [options] [paths…]
| Option | What it does |
|---|---|
code . | Open the current folder |
-r, --reuse-window | Open in the last active window |
-n, --new-window | Open in a new window |
-g file:line[:col] | Go to a line: code -g app.js:42 |
-d a b, --diff | Compare two files |
-m a b base result | Three-way merge |
-a folder | Add a folder to the current window |
-w, --wait | Wait until the file is closed (Git editor: code --wait) |
--install-extension id | Install an extension (--uninstall-extension to remove) |
--list-extensions | Installed extensions (--show-versions for versions) |
--profile "Name" | Open with a profile |
--disable-extensions | Start without extensions (troubleshooting) |
-v | Version |
winptyGit Bash helper that makes interactive Windows programs work in the mintty window.
| Usage | What it does |
|---|---|
winpty python | Python REPL that accepts input |
winpty node | Node.js REPL |
winpty docker exec -it app sh | Interactive container shell |
alias python='winpty python.exe' | Make it permanent in ~/.bashrc |
cmdStart the Command Prompt, or run one cmd command. cmd [options]
| Option | What it does |
|---|---|
/c "dir" | Run a command and close (cmd //c "dir" in Git Bash) |
/k "echo hi" | Run a command and stay open |
/q | Turn off command echo |
/s | Strip the outer quotes of the command |
/v:on | Delayed variable expansion (!var!) |
/u | Output Unicode to files and pipes |
/e:on | Command extensions (default on) |
sourceRun a script in the current shell, so its variables, aliases and functions stay. source file [args]
| Usage | What it does |
|---|---|
source ~/.bashrc | Reload your Bash settings after editing them |
. ~/.bashrc | Same: . is the POSIX spelling of source |
source .venv/bin/activate | Activate a Python virtual environment |
source .env | Load KEY=value lines as shell variables |
set -a; source .env; set +a | …and export them to programs you start |
Nothing on this sheet matches “”.