Set your name and email (once per computer)
git config --global user.name "Your Name" git config --global user.email "you@example.com"
Every commit records an author; set it before your first commit.
Loadingโฆ
Search everyday Git tasks, from undoing a commit to rebasing a branch, and copy the exact commands with what they do and when to be careful.
Also covers: Git cheat sheet ยท Git commands list ยท How to undo a git commit
43 tasks
git config --global user.name "Your Name" git config --global user.email "you@example.com"
Every commit records an author; set it before your first commit.
git config --global init.defaultBranch main
New repositories start on main instead of master.
git init
Turns the current folder into a Git repository.
git clone https://github.com/user/repo.git
Downloads the repository and its full history into a new folder.
git status
Shows modified, staged, and untracked files, and the current branch.
git diff git diff --staged
The first shows unstaged changes; the second, what's staged for the next commit.
git add file.txt git add .
Adds one file, or everything changed in the current folder and below.
git add -p
Walks through each change and asks whether to stage it.
git commit -m "Describe the change"
Saves a snapshot with a message. Write it in the imperative: "Add login form".
git commit -am "Describe the change"
Commits all modified tracked files; new (untracked) files still need git add.
git rm --cached file.txt
Useful after adding something to .gitignore that was already committed.
git mv old.txt new.txt
Moves the file and stages the rename.
git branch git branch -a
Local branches, or local and remote ones.
git switch -c feature/login
Creates the branch from where you are and switches to it.
git switch main
Changes your working files to that branch. Commit or stash changes first.
git switch main git merge feature/login
Brings the feature branch's commits into main.
git fetch origin git rebase origin/main
Replays your commits on top of main for a straight history.
โ Rewrites your branch's commits. Don't rebase a branch others are working on.
git branch -d feature/login git push origin --delete feature/login
Deletes it locally (only if merged), then on the remote. Use -D to force the local delete.
git branch -m new-name
Renames the branch you're on.
git remote add origin https://github.com/user/repo.git git push -u origin main
Adds the remote, pushes main, and sets it as the default upstream.
git push
Uploads commits on the current branch to its upstream.
git push -u origin feature/login
Creates the branch on the remote and links it, so later git push and git pull just work.
git pull
Fetches and merges the remote branch into yours.
git fetch
Updates your view of the remote; your branches are untouched until you merge or rebase.
git remote -v
Lists remote names and their URLs.
git restore file.txt
Puts the file back to the last committed version.
โ Uncommitted changes to that file are lost.
git restore --staged file.txt
Removes it from the next commit; your edits stay in the file.
git add forgotten.txt git commit --amend -m "Better message"
Replaces the last commit with a corrected one.
โ Only amend commits you haven't pushed yet.
git reset --soft HEAD~1
Moves the branch back one commit; the changes stay staged.
โ Avoid on commits already pushed and shared.
git reset --hard HEAD~1
Removes the commit and its changes from your branch.
โ Deletes work. Recoverable for a while with git reflog.
git revert <commit>
Makes a new commit that reverses the old one, without rewriting history. Safe on shared branches.
git reflog
Lists everywhere HEAD has been; git switch -c rescue <hash> brings a commit back.
git merge --abort git rebase --abort
Returns to the state before you started.
git clean -n git clean -fd
The first lists what would be deleted; the second deletes untracked files and folders.
โ git clean -fd can't be undone.
git log --oneline --graph --all
One line per commit, with branches drawn as a graph.
git log -p -- file.txt
Every commit that touched the file, with its changes.
git blame file.txt
Shows the commit and author for every line.
git show <commit>
The message, author, and full changes of a commit.
git log --grep="login"
Lists commits whose message mentions the text.
git stash push -m "work in progress"
Saves uncommitted changes and gives you a clean working folder.
git stash list git stash pop
Lists stashes, then reapplies the latest and removes it from the stash.
git tag -a v1.0.0 -m "Version 1.0.0" git push origin v1.0.0
Creates an annotated tag and pushes it; tags aren't pushed by default.
git cherry-pick <commit>
Applies that single commit on top of your current branch.
Commands use current Git (2.23 or later: git switch and git restore). Replace placeholders like <commit> with a commit hash from git log --oneline.
Type a task in plain words: undo commit, new branch, delete branch, stash, rebase.
Each command comes with a short explanation and a warning when it can lose work or rewrite shared history.
Copy the command, replace placeholders like <commit> with your own values, and run it in your terminal.
git reset moves your branch back, removing commits from it, which is fine before pushing. git revert adds a new commit that undoes an old one, the safe choice for commits others already have.
Since Git 2.23, git switch changes branches and git restore discards file changes. git checkout still works for both, but the newer commands are clearer, so they're used here.
Usually, yes. git reflog lists every position your branch has been in; find the commit and run git switch -c rescue <hash> to bring it back.
No. The helper is a searchable list that runs in your browser.
Data
Format, validate, and minify JSON in your browser. Paste it, upload a file, or load it from a URL. Errors show the exact line and column.
C# / .NET
Paste JSON and get C# model classes or records, ready for System.Text.Json or Newtonsoft.Json. Nested objects, arrays, nullable types, dates, and GUIDs are inferred for you.
TypeScript
Paste JSON and get TypeScript interfaces or type aliases, with nested objects named for you, optional and nullable fields detected from every array item, and union types.
SQL
Turn a JSON array into a CREATE TABLE with inferred column types and batched INSERT statements for PostgreSQL, MySQL, SQL Server, or SQLite.
SQL
Format and beautify SQL queries for SQL Server (T-SQL), PostgreSQL, MySQL, Oracle, and more. Set the indentation, keyword case, and layout, and get the exact line of any syntax error.
Data
Format, validate, and minify XML (config files, .csproj, SOAP, RSS) in your browser. Entities, CDATA, and mixed content are kept exactly as written, and errors show the line and column.