Git stores everything in a directory, rm -rf .git to delete the git project
git --help command
Changing History
Reflog
Saves every instance of head changes
gitreflog#see list of head changes#Alternate ways to jump to reflog HEADSgitcheckout-bafter-commitHEAD@{1}gitresetHEAD@{1}
Get specific file from past
gitcheckout<treeish>--/path/to/dir/orfile.js
Rebase
rewrites history, if commits not local can mess things up
could also rebase all your branch commits to occur at end of current master to avoid a merge commit
git rebase master, rebases current branch to master one
Merge master in your branch before push
git pull --rebase origin master
Squash many commits to one
git rebase -i <COMMIT_TO_IGNORE>
Squash all but top
quit-save to rebase
Stash
git stash - Takes dirty changes and saves them without committing
git stash pop - Reapply last saved changes
git stash apply stash@{2}
Undoing Last Commit
git reset --hard HEAD~1 => don't keep changes
git reset --soft HEAD~1 => undo commit, but keep working changes
git revert <commit to undo> =>Commit a commit undoing last commit
Remotes
git remote -v => List origins
Add remote
git remote add origin [github url]
Selecting branch to push from and to
Reset to remote branch
git checkout -B master origin/master //-B resets if it already exists
Other
List Branches By Last Modified
Tagging
git tag -a v1.4 -m "my version 1.4"
Delete branches
git branch -d <branchname>
git remote prune origin //remove all branches not in origin
Stop tracking file
git rm --cached <file>
Remove all Untracked files and build products
git clean -fd //remove everything untracked besides what is ignored by .gitignore git clean -fdx //remove all untracked files including those ignored by .gitignore git clean -fdX //only remove files ignored by .gitignore
for k in $(git branch | perl -pe s/^..//); do echo -e $(git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1)\\t$k; done | sort -r
git bisect start
git bisect bad #current version is bad
git bisect good v2.6.13
#Starts wizard and checks out midpoint
git bisect bad #depending on if good or bad
git bisect good
node_modules/ #any node_modules anywhere
/node_modules #only at route
*/node_modules #in any subdir
# Create a new worktree with a new branch
git worktree add ../project-feature-a -b feature-a
# Or create a worktree with an existing branch
git worktree add ../project-bugfix bugfix-123
# List all worktrees
git worktree list
# Remove a worktree when done
git worktree remove ../project-feature-a
# Navigate to your worktree
cd ../project-feature-a
# Run Claude Code in this isolated environment
claude