# Get the last commit SHA
git log -1 --format='%H' # long sha
git log -1 --format='%h' # short sha
Get the branch name only.
git rev-parse --abbrev-ref HEAD
List changed files.
# Including whitespace changes
git diff --name-only
# README.md
# script.sh
# Excluding whitespace changes
git diff --name-only -w
# README.md
Force pull, basically. Do a hard reset on the current branch from the origin remote. Use with caution!
git reset --hard origin/dev
Get the latest release tag. Find the most recent tag beginning with "release-", followed by any number of digits.
git describe --tags --abbrev=0 --match "release-[0-9]*"
# release-55.11
Move branch from previous name to main
. Most often used to replace the now-archaic 'master' name.
git branch -M main
Get latest commit with the tag at $1
.
git rev-list -n 1 --tags="$1"
List all git tags in the repo.
git tag -l
Move a file (and, critically, tell git where it went!).
git mv ./oldName.txt ./newName.txt
List all branches.
git branch
List all branches on remote.
git branch --remotes
# OR
git branch -r
# origin/main