Skip to content

Instantly share code, notes, and snippets.

@TimothyJones
Last active August 21, 2021 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimothyJones/25670501d11b43a7e06039ffed887898 to your computer and use it in GitHub Desktop.
Save TimothyJones/25670501d11b43a7e06039ffed887898 to your computer and use it in GitHub Desktop.
Tim's awesome command cheatsheet

Prettier

Format all files in src:

prettier --config .prettierrc --write "src/**/*.js"

Or, more generally:

prettier --config <path-to-config> --write "<source-path>/**/*.js"

Note that the quotes are required for the recursion to work correctly.

Git

Merge a branch ready to be reviewed:

git merge --squash --no-commit <branch-name>

Delete unnecessary branch:

git push origin --delete <branch_name>   # Delete from server
git branch -d <branch_name>              # Delete locally

Forgetting commits:

git reset --hard HEAD^   # Forget most recent
git reset --hard HEAD~2  # Forget last 2 commits (etc)

Change origin of your branch (eg to a fork)

git remote --set-url origin <your git clone URL>

Sharing a repo

On the source:

git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose

On the destination:

git clone git://<ip-address>/repo-name
git pull

Show the diff of the most recent stash:

git stash show -p

Vim

Comment lines containing log:

:g/log/s/^/\/\/

or more generally:

:g/<pattern>/s/^/<comment-string>

Saving over a read-only file

:w !sudo tee %

Usage strings

From man man or man man-pages or man manpages, depending on your system

The following conventions apply to the SYNOPSIS section and can be used
as a guide in other sections.

bold text          type exactly as shown.
italic text        replace with appropriate argument.
[-abc]             any or all arguments within [ ] are optional.
-a|-b              options delimited by | cannot be used together.
argument ...       argument is repeatable.
[expression] ...   entire expression within [ ] is repeatable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment