Skip to content

Instantly share code, notes, and snippets.

@OleksandrKucherenko
Last active March 27, 2023 09:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleksandrKucherenko/b325e857e60cbf397322ebb6b9014018 to your computer and use it in GitHub Desktop.
Save OleksandrKucherenko/b325e857e60cbf397322ebb6b9014018 to your computer and use it in GitHub Desktop.
GIT useful commands
#!/bin/bash
# Get root folder path of the project under git
# Output: /Users/oleksandr.kucherenko/projects/klarna-app
git rev-parse --show-toplevel
# Get latest commit hash
# Output: 1b03718dabad03aaef917eff3ea8bb15e4fa1c46
git rev-parse @
# List branches with specific commit
# Output: list of branches
git branch -r --contains $(git rev-parse @)
# Get current branch name
# Output: master
git rev-parse --abbrev-ref @
# alternative syntax to written above. is commit in master branch?
# Output:
# origin/HEAD -> origin/master
# origin/master
git rev-parse @ | xargs -I _ git branch -r --contains _ | grep master
#
# Update master branch without switching to it
#
git fetch origin master:master --tags
#
# Update list of available branches from remote repo (prune/delete old branches)
#
git remote update origin --prune
###
### Bash hacks
###
# Get user name with fallback: $LDAP_USERNAME -> $AD_USERNAME -> $USER
SLACK_USERNAME=${LDAP_USERNAME:-${AD_USERNAME:-${USER}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment