A cheatsheet of commands for my workflow.
-
cd – go to home
-
cd ~/Desktop – absolute path
-
cd .. – up one directory
-
pwd – print current path
-
ls – names
-
ls -la – incl. hidden + details
- git status – what's changed/staged?
- git status -sb – short, with branch
- git diff – unstaged changes
- git diff --staged – staged changes
- 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)
- 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
- 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
- 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
- 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
- git checkout
- git fetch origin
- git rebase origin/main
- git add
- git rebase --continue
- git push --force-with-lease
- git stash – stash tracked changes
- git stash -u – include untracked
- git stash list
- git stash pop – restore & remove from stash
-
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
- git log --oneline --graph --decorate --all
- git blame
- git show
- git diff ..
- git diff --name-only HEAD~1
- git tag v1.0.0
- git tag -a v1.0.0 -m "msg"
- git push origin v1.0.0
- git push --tags
- git remote add origin
- git remote set-url origin
- git fetch origin --prune
node_modules/ *.log .env .DS_Store
- git rm -r --cached .
- git add .
- git commit -m "apply .- gitignore"
- 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"
- git push -u origin
- git branch -m
- git push origin :
- git push -u origin
- git fetch origin
- git rebase origin/main