Skip to content

Instantly share code, notes, and snippets.

@themouette
Last active May 26, 2020 14:32
Show Gist options
  • Save themouette/bd082954dc0a8f091a3e7c25e91fe547 to your computer and use it in GitHub Desktop.
Save themouette/bd082954dc0a8f091a3e7c25e91fe547 to your computer and use it in GitHub Desktop.
check git branches status
# Find common ancestor of 2 branches:
git rev-parse BRANCH1 BRANCH2
# Last commit date (relative time) on BRANCH
git --no-pager for-each-ref BRANCH --format='%(committerdate:relative)'
# Last commit date on BRANCH
git --no-pager show --format='%ai'
# Last commit author on BRANCH
git --no-pager show --format='%an'
# Last commit message on BRANCH
git --no-pager show --format='%s'
# Last commit for BRANCH
git --no-pager rev-parse BRANCH
# Branch name from commit / fullbranch name from branch name
git --no-pager rev-parse --symbolic-full-name BRANCH
# Find remote for BRANCH
upstream = git --no-pager rev-parse --symbolic-full-name BRANCH
if upstream startsWith('refs/remotes/'): return upstream
try:
upstream = git --no-pager rev-parse --symbolic-full-name "${BRANCH}@{u}"
return upstream
catch:
upstream = git --no-pager rev-parse --symbolic-full-name "remotes/origin/${BRANCH}"
if upstream: return upstream
else retun None
# List branches merged in BRANCH
git --no-pager branch --sort=committerdate --format=%(refname:short) --merged BRANCH
# List branches not merged in BRANCH
git --no-pager branch --sort=committerdate --format=%(refname:short) --no-merged BRANCH
# List remote branches (--no-)merged in BRANCH
git --no-pager branch --remotes --sort=committerdate --format=%(refname:short) --merged BRANCH
# List remote branches (--no-)merged in BRANCH matching PATTERN
git --no-pager branch --remotes --list PATTERN --sort=committerdate --format=%(refname:short) --merged BRANCH
@themouette
Copy link
Author

This is everything needed to look for branches status differences between branches and remote vs local

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