Skip to content

1980computer/cheat-sheet-terminal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

Cheat sheet

A cheatsheet of commands for my workflow.

Local Navigation (Shell)

  • cd – go to home

  • cd ~/Desktop – absolute path

  • cd .. – up one directory

  • pwd – print current path

  • ls – names

  • ls -la – incl. hidden + details

Inspect Repo State

  • git status – what's changed/staged?
  • git status -sb – short, with branch
  • git diff – unstaged changes
  • git diff --staged – staged changes

Working with an Existing Repo

  • git clone – HTTPS or SSH
  • cd
  • git remote -v – view remotes
  • git fetch – update refs (no merge)
  • git pull – fetch + merge (or rebase; see config below)

Day-to-Day: Add, Commit, Push

  • git add . – stage all modified/new files
  • git add -p – stage hunks interactively
  • git commit -m "meaningful msg" – commit staged changes
  • git push -u origin – first push; sets upstream
  • git push – subsequent pushes

Starting a Brand-New Repo

  • git init
  • git add --all
  • git commit -m "initial commit"
  • git branch -M main – (optional) rename to main
  • git remote add origin
  • git push -u origin main

Branching & Switching

  • git branch -av – list local & remote branches
  • git branch – create branch
  • git checkout – switch (old syntax)
  • git switch – switch (newer, nicer)
  • git switch -c – create + switch

Merging (Safe Workflow)

  • git checkout main
  • git pull --ff-only – update main safely
  • git checkout
  • git merge main – bring latest main into feature
  • git checkout main
  • git merge – merge feature into main
  • git push

Rebasing (Optional)

  • git checkout
  • git fetch origin
  • git rebase origin/main
  • git add
  • git rebase --continue
  • git push --force-with-lease

Stashing

  • git stash – stash tracked changes
  • git stash -u – include untracked
  • git stash list
  • git stash pop – restore & remove from stash

Undo & Recover

  • git restore – discard unstaged changes

  • git checkout -- – older syntax

  • git reset HEAD – unstage a staged file

  • git reset --soft HEAD~1 – undo commit, keep staged

  • git reset --mixed HEAD~1 – undo commit, keep changes unstaged

  • git reset --hard HEAD~1 – undo commit AND changes

  • git revert – make a new commit that undoes

  • git reflog – find lost commits & HEAD moves

Logs & History

  • git log --oneline --graph --decorate --all
  • git blame
  • git show

Comparing Things

  • git diff ..
  • git diff --name-only HEAD~1

Tags (Releases)

  • git tag v1.0.0
  • git tag -a v1.0.0 -m "msg"
  • git push origin v1.0.0
  • git push --tags

Remotes

  • git remote add origin
  • git remote set-url origin
  • git fetch origin --prune

.- gitignore Example

node_modules/ *.log .env .DS_Store

To apply .- gitignore after adding files:

  • git rm -r --cached .
  • git add .
  • git commit -m "apply .- gitignore"

Useful Config

  • git config --global user.name "Your Name"
  • git config --global user.email "[email protected]"
  • git config --global pull.rebase true
  • git config --global init.defaultBranch main
  • git config --global alias.lg "log --oneline --graph --decorate --all"

Common Fixes for Push

  • git push -u origin
  • git branch -m
  • git push origin :
  • git push -u origin
  • git fetch origin
  • git rebase origin/main

About

A cheatsheet of commands for my workflow.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published