Checking Status

  • git status is the end-all know-all. it will never hurt you. Embrace it; it is inevitable.
    • git status --porcelain for programmatic parsing

Staging

  • git add <file> - add files to the staging area
    • git add -p <file> - interactively pick hunks to stage / not stage
    • git add -A - add all files, tracked and untracked
  • git restore --staged - remove files from the staging area (unstage changes)
    • git restore --staged -p - interactively pick hunks to unstage / keep staged

Committing

  • git commit -m "message" - commit staged changes with the given message
  • git commit -e - commit, but open an interactive editor to write the (optionally multi-line) commit message
    • git config --global core.editor "vim" to select the editor executable
  • git commit -a - automatically commit all changed files, even if not previously staged
    • This does not add untracked files; only commits changes to already-tracked files
  • git commit -s “sign-off” the commit message automatically
    • Adds a message line containing Signed-off-by: <yourname> <youremail>
    • Required by some projects and treated as analogous to a handwritten signature on the change
  • git commit -S - sign the commit cryptographically with GPG (you must have a GPG key configured for this)

git