Skip to content

Instantly share code, notes, and snippets.

@lewxdev
Last active October 16, 2024 18:13
Show Gist options
  • Save lewxdev/1a371535daa2439dc7e632af8b8c973b to your computer and use it in GitHub Desktop.
Save lewxdev/1a371535daa2439dc7e632af8b8c973b to your computer and use it in GitHub Desktop.

git commands

what I've picked up over the years about the stupid content tracker

🚽 porcelain

git clean -dfx [<path>...]

delete untracked paths from the working tree. use -dfX for ignored paths.

e.g. before building or debugging to ensure a clean environment

git restore -s origin/<branch> <path>

restore a working tree path from an origin branch.

e.g. when resolving conflicts or depending on files on another remote branch

git switch -

switch to the previously checked-out branch

e.g. when switching to and from the main branch from a feature branch

git switch -c <new-branch> [<source-branch>]

create and switch to a <new-branch> off of an optional <source-branch>.

e.g. when starting work on a new feature branch

🔩 plumbing

git update-index --assume-unchanged <path>

ignore changes for a tracked path

e.g. when repository tracks sensitive files like .env*

additional resources

Footnotes

  1. restore and switch are newer, generally syntactically equivallent commands to checkout. these new commands were introduced in Git 2.23 (circa 2019) to reduce the confusion around checkout. (see Git switch vs Git checkout) 2

@lewxdev
Copy link
Author

lewxdev commented Oct 16, 2024

need to add git merge, git rebase, and git diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment