Not everyday git tricks

Empty a branch (delete all commit history)

  1. git checkout --orphan tmp
  2. git rm -rf *
  3. git commit --allow-empty -m "empty repo"
  4. git branch -m master
  5. git push -f origin master

Parallelize Development

git worktree add ../new-worktree-dir some-existing-branch

The folder ../new-worktree-dir contains the same repo but on the some-existing-branch. They share the same .git directory, which makes it more convenient to switch to another branch and using a different environment.

List all node_modules that are npm linked in current repo

find node_modules -maxdepth 1 -type l -ls

List all globally linked modules

npm ls -g --depth=0 --link=true

Unlink a npm linked module

npm unlink --no-save module-name

Remove all the untracked files

git clean -f -d

Search through history

git log --patch | less +/searching_string

Stash with untracked

git stash -u

Interactively Stash Selected Parts of Files

git stash -p

Revert File to Previous Commit

git checkout <commit_hash> -- <file>

Ignore certain file in git without touching .gitignore

git update-index --skip-worktree <file>
git update-index --no-skip-worktree <file>

How to disable git gpg signing

git config commit.gpgsign false