Set my name and email Safegit config --global user.name "Your Name"
git config --global user.email "you@example.com"Sets the identity stored in every commit you make.
Setup
Start a new repository SafeCreates a .git folder in the current directory.
Setup
Downloads the repo with its full history into a new folder.
Setup
Clone only the latest snapshot (fast) Safegit clone --depth 1 <url>Shallow clone: only the newest commit, much smaller and faster.
Setup
Use main as the default branch name Safegit config --global init.defaultBranch mainNew repositories start on main instead of master.
Setup
git config --list --show-originLists every setting and the file it came from.
Setup
See what changed (status) SafeShows staged, unstaged and untracked files and your branch.
Inspect
Compact one-line-per-file status with branch info.
Inspect
Shows line-by-line differences not yet staged.
Inspect
Shows what will go into the next commit.
Inspect
See history as a graph Safegit log --oneline --graph --decorate --allCompact commit history with branches drawn as a graph.
Inspect
Displays the message and the changes of a commit.
Inspect
See what the last commit changed SafeSummary of files changed in the latest commit.
Inspect
See the history of one file Safegit log --follow -p -- <file>Every change to a file, following renames.
Inspect
Find who changed a line (blame) SafeShows the commit and author for each line.
Inspect
Search commit messages SafeLists commits whose message contains the text.
Inspect
Search code history for a string Safegit log -S"<text>" --onelineFinds commits that added or removed that string.
Inspect
Find the commit that broke something Safegit bisect start
git bisect bad
git bisect good <commit>Binary search through history; mark each step good or bad until the culprit is found.
Inspect
Shows what feature has that main does not.
Inspect
See where HEAD has been (recover lost commits) SafeA log of every position HEAD has had. Lets you find "lost" commits.
Inspect
List files git tracks SafePrints every file under version control.
Inspect
Stages new, modified and deleted files.
Commit
Stage only parts of a file SafeInteractively choose which hunks to stage.
Commit
Commit staged changes SafeRecords the staged snapshot with a message.
Commit
Commit all tracked changes at once SafeStages modified tracked files and commits. Does not add new files.
Commit
git restore --staged <file>Removes the file from the next commit but keeps your edits.
Commit
Fix the last commit message Cautiongit commit --amend -m "new message"Rewrites the latest commit. Avoid if already pushed.
Commit
Add a forgotten file to the last commit Cautiongit add <file>
git commit --amend --no-editFolds the file into the previous commit, keeping its message.
Commit
Undo last commit but keep the changes CautionMoves the branch back one commit; changes stay staged.
Undo
Undo last commit and unstage the changes CautionMoves back one commit; changes stay in your files, unstaged.
Undo
Undo last commit and DISCARD the changes DestructiveMoves back one commit and throws away its changes.
Undo
Discard changes in one file DestructiveResets the file to the last commit. Uncommitted edits are lost.
Undo
Discard ALL local changes DestructiveResets tracked files to HEAD. Uncommitted work is lost.
Undo
Delete untracked files DestructiveRemoves untracked files and folders. Try git clean -nd first to preview.
Undo
Undo a pushed commit safely SafeCreates a new commit that reverses the old one. Safe for shared branches.
Undo
Returns to the state before the merge started.
Undo
Restore a file from an older commit Cautiongit restore --source=<commit> -- <file>Brings back that version of the file into your working tree.
Undo
Get back a commit I reset by mistake Destructivegit reflog
git reset --hard <commit>Find the commit in the reflog, then move the branch back to it.
Undo
Shows local branches; the current one is starred.
Branches
Create and switch to a new branch SafeMakes a branch from here and moves to it.
Branches
Moves to an existing branch.
Branches
Rename the current branch CautionRenames locally. Update the remote separately.
Branches
Delete a merged branch SafeRefuses if the branch has unmerged work.
Branches
Force-delete an unmerged branch DestructiveDeletes even with unmerged commits, which may become hard to find.
Branches
Delete a branch on the remote Cautiongit push origin --delete <name>Removes the branch from the remote repository.
Branches
Shows branches known from the remote.
Branches
Push a new branch and set its upstream Safegit push -u origin <name>Publishes the branch and links it so later git push/pull just work.
Branches
Merge a branch into the current one SafeCombines the branch's history into where you are.
Merge & rebase
Rebase my branch onto main CautionReplays your commits on top of main for a linear history. Rewrites commits.
Merge & rebase
Squash the last 3 commits CautionInteractive rebase: mark commits as squash or fixup. Rewrites history.
Merge & rebase
Cancels the rebase and restores the branch.
Merge & rebase
Copy one commit to this branch SafeApplies that commit's changes as a new commit here.
Merge & rebase
List files with merge conflicts Safegit diff --name-only --diff-filter=UShows unmerged files. Edit them, then git add and continue.
Merge & rebase
Keep my version (or theirs) in a conflict Cautiongit checkout --ours <file>
git checkout --theirs <file>Picks one side of the conflict for that file. In a rebase, ours/theirs are swapped.
Merge & rebase
git remote add origin <url>Names a remote repository so you can push and pull.
Remotes
Lists remote names and URLs.
Remotes
git remote set-url origin <new-url>Points origin somewhere else (for example SSH instead of HTTPS).
Remotes
Download updates without merging SafeUpdates remote-tracking branches; your files do not change.
Remotes
Pull and rebase instead of merge CautionFetches then replays your local commits on top, avoiding merge commits.
Remotes
Uploads your commits to the tracked remote branch.
Remotes
Force push safely after a rebase Destructivegit push --force-with-leaseOverwrites the remote branch only if nobody else pushed meanwhile.
Remotes
Save work without committing (stash) SafeShelves tracked changes so you can switch branches.
Stash
Stash including new files SafeAlso stashes untracked files.
Stash
Shows all stashed changes.
Stash
Bring back stashed work SafeRe-applies the latest stash and removes it from the list.
Stash
Delete a stash DestructiveRemoves the latest stash permanently.
Stash
git tag -a v1.0.0 -m "Release 1.0.0"Annotated tag marking this commit.
Tags
Uploads all local tags to the remote.
Tags
Deletes the tag locally. Remove it remotely with git push origin :refs/tags/<tag>.
Tags
Stop tracking a file but keep it on disk CautionUse after adding the file to .gitignore.
Files
Rename or move a file SafeRenames and stages the change in one step.
Files
Delete a file from the repo CautionDeletes the file and stages the removal.
Files
See which files are ignored SafeLists files matched by .gitignore.
Files