Skip to content

Instantly share code, notes, and snippets.

@socketbox
Last active June 14, 2023 13:41
Show Gist options
  • Save socketbox/ca760996ece5f42ccb53483d4734841b to your computer and use it in GitHub Desktop.
Save socketbox/ca760996ece5f42ccb53483d4734841b to your computer and use it in GitHub Desktop.
Commands and tricks for git

Branches

Get the SHA of the last commit on a remote branch:
git ls-remote [email protected]:org/repo.git branch_name | awk -F '\t' '{ print $1 }'

Delete remote branch
git push -d <remote_name> <branchname>

Diffs

Get a diff between the remote repo of a subtree and the subtree directory of a dependent project:
git diff -w -G upstream-subtree-repo/main main:subtree-repo-directory

Or to see a specific file at a specific commit (where ad893d21 is a commit in the upstream subtree repo):
git diff -w --compact-summary ad893d21:.github/CODEOWNERS main:subtree-repo-directory/.github/CODEOWNERS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment