git

Remove Git Submodule Completely

git submodule deinit -f path/to/submodule
git rm -f path/to/submodule
rm -rf .git/modules/path/to/submodule

# or in 1 line
S="path/to/submodule" && git submodule deinit -f "$S" && git rm -f "$S" && rm -rf ".git/modules/$S"

Search the whole git history

git grep "SEARCH_FOR" $(git rev-list --all)

Revert a file to its staged version (discarding only the unstaged edits)

git restore PATH_TO_FILE

Discard all changes inside a folder

git clean -fd FOLDER/
git restore "FOLDER/*" # quotes matter!

# in 1 command:
cd FOLDER && git clean -fd ./ && git restore "./*"

Restore a single file to its state from N commits ago

git restore PATH_TO_FILE --source=HEAD~N

(available in Git 2.23+)

Remove untracked files

git clean -i

Delete tag locally and remotely at once

DEL_TAG=v1.0.0; git tag -d $DEL_TAG && git push origin --delete $DEL_TAG

GitHub Tricks

CLI

gh issue develop 71 --checkout

What this does
: Creates a development branch on GitHub linked directly to issue #71.

--checkout: Automatically pulls that new branch down to your local machine and switches your Git workspace to it.

Shame on GitHub

https://httpie.io/blog/stardust

GitHub web editor

Hidden feature in GitHub web editor: you can move a line of code up or down by holding Option (on Mac) or Alt (on Windows/Linux) and pressing the Up or Down arrow keys!

Automatically sync code snippets in your README with GitHub Actions

https://www.reddit.com/r/TricksForGeeks/comments/1pk9wr6/automatically_sync_code_snippets_in_your_readme/

Generate a license for your repo

brew install gh
# This pulls the legal text from GitHub's API and saves it as a file
gh repo license view CC-BY-SA-4.0 > LICENSE

Cool stuff


PS: Smile 🤓

Git typo of the day:

git rest --hard