Skip to content

Instantly share code, notes, and snippets.

@jdalley
Last active July 3, 2021 03:09
Show Gist options
  • Save jdalley/79e299ea679b2e94d92c1478725e0141 to your computer and use it in GitHub Desktop.
Save jdalley/79e299ea679b2e94d92c1478725e0141 to your computer and use it in GitHub Desktop.
Git Things

Git Things

Useful things you can do with git.

  • Cross-repository issue tagging:
    • [org/repo#407]
  • Reset local branch to match origin (throw away local commits):
    • git reset --hard origin/<branch_name>
  • See diff between local and remote:
    • git diff origin/main..HEAD
  • See files changed between local and origin after a fetch:
    • git diff --name-only ..origin
  • See the log plus a diff for each commit that touched the named file:
    • git log -p <filename>
  • See a list of which commits are on one branch but not another:
    • git log main..feature/#1854
  • Prune local from remote:
    • git fetch --prune
    • git branch -v check for any branches marked "[gone]"
    • git branch -d [branch name] on any orphaned tracking branches
  • Delete local branches that have been pruned (have to run on Linux):
    • git branch --v | grep "\[gone\]" | awk '{print $1}' | xargs git branch -D
  • Delete local branches removed on remote using an NPM package: git-removed-branches
    • npm install -g git-removed-branches
    • View the stale local branches: git removed-branches
    • Delete the stale local branches: git removed-branches --prune
  • List files in a given path that changed in the last X days, that end with .css
    • git diff --stat "@{500.days.ago}" -- ./\*.css
  • Stash local changes, pull new changes (rebases if needed), pops the changes back off the stash:
    • git pull --rebase --autostash
  • Get a list of branches with Author:
    • git for-each-ref --format=' %(authorname) %09 %(refname)' --sort=authorname
  • Determine if the right branch is ahead of the left branch in commits:
    • git rev-list --count main..releases/03.11.2020
  • Push the current branch to the same name at origin:
    • git push -u origin HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment