FahamLah

Commands

One page per command. What it does, when to use it, how risky it is.

Terminal basics

  • pwdShows the folder you are in right now.Risk: Safe
  • lsLists the files and folders here.Risk: Safe
  • cdMoves you into another folder.Risk: Safe
  • mkdirMakes a new folder.Risk: Safe

Set up

Save your work

  • git initMakes a folder into a Git repo.Risk: Safe
  • git statusShows what changed and what is in the box.Risk: Safe
  • git addPuts changes in the box (staging area).Risk: Safe
  • git commitSaves the box as a save point.Risk: Safe
  • git rmDeletes a file and tells Git.Risk: Careful
  • git mvRenames or moves a file.Risk: Safe

Look at history

  • git logLists your save points, newest first.Risk: Safe
  • git showShows one commit and what it changed.Risk: Safe
  • git diffShows the changed lines. Red removed, green added.Risk: Safe
  • git branchLists branches. A star shows where you are.Risk: Safe

Undo things

  • git restorePuts a file back to a saved version.Risk: Can lose work
  • git resetMoves your branch back to an older commit.Risk: Careful
  • git revertMakes a new commit that undoes an old one.Risk: Safe
  • git switchMoves HEAD to a branch, or to a commit.Risk: Safe
  • git checkoutThe older way to switch branches or visit commits.Risk: Careful
  • git cleanDeletes untracked junk files.Risk: Can lose work
  • git reflogShows every place HEAD has been.Risk: Safe
  • git filter-repoRewrites history, for example to wipe a file from every commit. A separate tool you install.Risk: Can lose work

Branches and merging

  • git branchMakes, renames or deletes a branch. A branch is a sticky note on a commit.Risk: Careful
  • git switchMakes a new branch and moves you onto it.Risk: Safe
  • git mergeJoins another branch's work into the branch you are on.Risk: Safe
  • git stashPuts your unsaved changes in a drawer, so your folder is clean.Risk: Careful
  • git rebaseReplays your commits on top of another branch. You get new commits.Risk: Careful
  • git cherry-pickCopies one commit from somewhere else onto your branch.Risk: Safe

Work with GitHub

  • git remoteLists or saves remotes: short names for online copies of your project.Risk: Safe
  • git pushSends your new commits to the remote, like GitHub.Risk: Careful
  • git pushOverwrites the remote branch with yours. Other people's commits there can be lost.Risk: Can lose work
  • git cloneCopies a whole project, with all its history, to your computer.Risk: Safe
  • git fetchDownloads news from the remote. Your own branches stay the same.Risk: Safe
  • git pullFetches, then joins the new commits into your branch.Risk: Careful
  • git tagPuts a name that never moves on a commit, like v1.0.Risk: Safe

GitHub tools

  • ghCopies a GitHub repo to your computer, like git clone.Risk: Safe
  • ghMakes your own copy (a fork) of a repo in your GitHub account.Risk: Safe
  • ghOpens a new issue on GitHub from your terminal.Risk: Safe
  • ghLists the open issues in this repo.Risk: Safe
  • ghOpens a pull request for your current branch.Risk: Safe
  • ghBrings a pull request's branch to your computer and switches to it.Risk: Safe
  • ghStarts a new Codespace: a computer in the cloud for a repo.Risk: Safe

Deep Git

  • git cat-fileShows one object from inside Git: a commit, tree, blob or tag.Risk: Safe
  • git hash-objectPrints the id Git gives a file's content.Risk: Safe
  • git ls-treeLists the files and folders inside one tree.Risk: Safe
  • git rev-parseTurns a name like HEAD~2 or main into a full commit id.Risk: Safe
  • git logFinds commits by what they changed, who made them, or their message.Risk: Safe
  • git grepSearches the files Git tracks for a word or pattern.Risk: Safe
  • git blameShows who last changed each line of a file, and in which commit.Risk: Safe
  • git shortlogGroups the commits by author.Risk: Safe
  • git bisectFinds the commit that broke something by halving the history.Risk: Careful
  • git worktreeOpens a second working folder for the same repo.Risk: Careful
  • git configMakes a short name for a Git command you type often.Risk: Safe
  • git show-refLists your refs (branches and tags) with the commit id of each.Risk: Safe
  • git pack-refsMoves many small ref files into one file, .git/packed-refs.Risk: Safe
  • git gcTidies the repo: packs objects and throws away ones nothing can reach.Risk: Careful
  • git maintenanceKeeps a repo fast with small tidy-up jobs, in the background.Risk: Safe
  • git submoduleKeeps another repo inside yours, linked at one exact commit.Risk: Careful
  • git sparse-checkoutShows only some folders of a big repo in your working folder.Risk: Safe
  • git rerereRemembers how you fixed a conflict and replays the fix next time.Risk: Safe
  • git range-diffCompares two versions of a branch, commit by commit.Risk: Safe