Last active
March 27, 2023 09:37
-
-
Save OleksandrKucherenko/b325e857e60cbf397322ebb6b9014018 to your computer and use it in GitHub Desktop.
GIT useful commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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