Skip to content

Instantly share code, notes, and snippets.

@nataliemarleny
Last active October 19, 2021 09:50
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliemarleny/d57dc1a1a2af081fbb2c77afca9790a5 to your computer and use it in GitHub Desktop.
Save nataliemarleny/d57dc1a1a2af081fbb2c77afca9790a5 to your computer and use it in GitHub Desktop.
Niche git commands which I won't remember aliases for
[user]
name = <ur-name>
email = <ur-email>
[core]
editor = vim -f
excludesfile = /Users/<name-of-mac>/.gitignore_global
[color]
ui = true
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit
lga = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --all
ll = log --graph --format=medium
lla = log --graph --format=medium --all
ignored = ls-files --others -i --exclude-standard
# Shorthands
st = status
ci = commit
// THE PR REVIEWER (opens all files in that branch in vscode):
vscode $(git diff origin/develop..HEAD --name-only)
// this goes to ~/.bashrc
alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code'
// note - opens deleted files (might need to work on the command to change this)

// The Classic:
git push <remote> --delete <remote-branch-name-WITHOUT-THE-REMOTE>

// List files in a commit:
git diff-tree --no-commit-id --name-only -r <commit-id>

// Generate the patches for each log entry
git log -p <filename>

// Squash n commits
git rebase --interactive HEAD^(*n)
// manually add `squash` to the commits to be squashed

// THE PR Inspector 🔎
// When you're running test environments, they create a bunch of temp files
// Commands for when you're experiencing issues which aren't easily debuggable
git ignored | xargs rm -rf
git clean -xfd

// Show the excerpt of the git history/graph from origin/develop to <HEAD>
git lg origin/develop..HEAD
// or
git lg <branch-name>..<commit-id>
// or
git lg <commit-id>..<commit-id>

// Shows the changes between origin/develop and HEAD
git diff origin/develop..HEAD

// Show overview of insertions and deletions in files
git diff --stat origin/develop..HEAD

// Show the history of commits in which files were changed
git lg -- <path-to-file> <can-add-as-many-files-as-you-want>

// Show above but with the full commit message
git ll -- <path-to-file> <can-add-as-many-files-as-you-want>

// Keep all the changes in the code, but just get rid of the most recent commit
git reset --soft HEAD^

// Show git history for a file on a branch
git lg <brand-name> -p -- <path-to-file>

// Change the email you commit as:
// Read what is the current email:
git config user.email
// Write the desired email:
git config user.email <ur-email>

Interactively checks out the changes from the previous commit (meaning that you can choose what to revert)
Press yes for things you want to keep
git checkout -p HEAD^ -- .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment