Try out jj/jujutsu?
Investigate git grep
Git hooks to install npm packages: https://andycarter.dev/blog/automating-npm-and-composer-with-git-hooks
## Initial Configuration
# Set name and email in global configuration
git config --global user.name "John Nesky"
git config --global user.email nesky@google.com
# New branches leave associated remote branch unset instead of copying parent's
# Default to pushing branches to a branch with the same name on remote repo
# When pushing, automatically record the destination as the associated remote branch
git config --global branch.autoSetupMerge simple
git config --global push.default current
git config --global push.autoSetupRemote true
# Print global config
git config --global --list
## Repo Management
# Create a new empty repo in the current directory
git init
# Copy a remote repo into a child directory
# (via http or ssh)
git clone https://github.com/OWNER/REPOSITORY.git
git clone ssh://git@github.com/OWNER/REPOSITORY.git
git clone git@github.com:OWNER/REPOSITORY.git
# Display data about associated remote repository
git remote -v
git remote show origin
git remote show upstream
# Add a new remote repository
git remote add origin https://github.com/OWNER/REPOSITORY.git
git remote add origin ssh://git@github.com/OWNER/REPOSITORY.git
# Rewrite a repository's origin branch to use SSH
git remote set-url origin ssh://git@github.com/OWNER/REPOSITORY.git
# Add link to upstream repository
# (e.g. the original repo that your repo on github was forked from)
git remote add upstream git@github.com:google/blockly.git
git remote add upstream git@github.com:google/blockly-samples.git
git remote add upstream https://github.com/OWNER/REPOSITORY.git
## Branches
# List local branches
git branch
# List local and cached remote branches
git branch -a
# List local branches with associated remote branches
git branch -vv
# Switch to a named branch, replacing files in working directory with versions from branch
git checkout $branch
git switch $branch
# Make new branch based on current one and switch to it
git checkout -b $branch
git switch -c $branch
# Delete branch
git branch -d $branch
git branch --delete $branch
# Rename a branch
git branch -m $oldName $newName
# Copy all files as-is from the named branch into the working directory
git checkout $branch -- .
# List remote branches
git ls-remote --heads origin
## Staging files for commit
# Add file changes to stage
git add $filepath
# Stage all modified files
git add -u
# Stage all modified and untracked files
git add -A
# Stage the removal of files
git rm -r $filepath
# Check currently staged, modified, and untracked files
git status
# Unstage changes to file without reverting file in the working directory
git reset HEAD $filePath
# Unstage all staged changes without reverting files in the working directory
git reset
# Discard changes to a file
git checkout -- $filePath
## Comparing changed files
# Print diff of current unstaged changes in working directory
git diff
# Print diff of current staged changes in working directory
git diff --cached
git diff --staged
# Compare file in working directory to version in branch or commit
git diff #branchNameOrCommitHash -- filePath
# Compare branches, e.g. to preview before merging branches
git diff $sourceBranch $targetBranch
## Committing
# View commit history of current branch
git log
# Commit staged changes
git commit -m 'message'
# Undo last commit without reverting files in the working directory
git reset HEAD~1
# Undo last commit while leaving file changes staged
git reset --soft HEAD~1
# Undo last commit and discard modified files, checking out previous commit's files
git reset --hard HEAD~1
# Update user of last commit to name and email currently in configuration
git commit --amend --reset-author --no-edit
# Create new changes reverting changes in previous commit
git revert $commitId
# Print diff of last commit (doesn't work for merge commits)
git show HEAD
## Pulling and Pushing
# Update local branch by getting latest commits of associated remote branch
# (and merge with new local commits if necessary,
# but this can't merge with any uncommitted changes in workspace, see stashing)
git pull
# Pull changes from specific branch in remote origin repository
git pull origin $branch
# Pull changes from upstream repository
git pull upstream $branch
# Pull changes unless you have local-only commits that would need to be merged
git pull --ff-only
# Pull changes but instead of merging, rewrite history to put your local-only commits after remote commits
git pull --rebase
# Get and cache remote branch information without modifying your local branch
git fetch
# Push changes in current local branch to associated branch of remote repository
git push
# Push current local branch to specific branch of remote repository
git push origin $branch
# Push changes to specific branch of remote repository and remember that branch for later
git push -u origin $branch
# Delete a remote branch
git push origin --delete $branch
# Force push branch
# (necessary when your local commit history contradicts remote history,
# e.g. because you undid commits that were already pushed.)
# Warning: this will frustrate collaborators who have already started working from previously pushed history!
git push -f
## Merging
# Merge commits after shared ancestor from $branch into current branch.
# Merging accurately preserves history, unifying both branch timelines.
# If any files modified by both branches, user will be asked to audit merged files.
# The commit at the new tip of the current branch will have two parent commits.
# ("ours" = current branch, "theirs" = other given branch)
git merge $branch
# Rebase commits after shared ancestor from current branch onto $branch.
# The current branch's history will be moved to be descending from the tip of $branch.
# If any files modified by both, user will be asked to audit merged files.
# If current branch has multiple new commits, each will need to be rebased.
# ("theirs" = current branch, "ours" = other given branch)
git rebase $branch
# Resume rebasing after fixing conflicts and staging changes.
git rebase --continue
# Revert branch to state before the attempt to rebase.
git rebase --abort
# Copy file changes without commit history from another branch
git merge --squash $branch
## Stashing
# Temporarily stash and revert current changes in a dirty workspace,
# leaving a clean checkout that can be merged with other commits or branches.
git stash
git stash push
# List id and info about current stashes
git stash list
# Apply and merge changes and remove latest stash entry, renumbering others
git stash pop
# Apply changes and preserve stash entry using id from stash list
git stash apply stash@{n}
# Stash changes without reverting staged changes and use custom name
git stash push --staged --keep-index -m "my_name"
# Apply changes with custom name (via regex) and preserve stash entry
git stash apply stash^{/my_name}
# List changed files of stash
git stash show stash@{n}
# List diff of stash
git stash show -p stash@{n}
# Delete a stash entry (renumbering others)
git stash drop stash@{n}
# Remove all stashed entries
git stash clear
## npm
# similar to npm link but fewer footguns: https://hirok.io/posts/avoid-npm-link
npm install --no-save ../path/to/package
# grep all folders except node_modules
grep -rin 'expression' . --exclude-dir=node_modules