# Get the current commit hash of HEAD (the latest commit on the current branch)
git rev-parse @
# Get the current branch name (using "@" as shorthand for "HEAD" or the current branch)
git rev-parse --abbrev-ref @
# Commit with the current branch name as the commit message (useful for quick commits labeled by branch name)
git commit -m "$(git rev-parse --abbrev-ref @)"
# Commit with the branch name as the message, even if there are no changes (useful for placeholder commits)
git commit -m "$(git rev-parse --abbrev-ref @)" --allow-empty
# Push the current branch to the origin remote repository
git push origin "$(git rev-parse --abbrev-ref @)"
# Pull the origin remote repository of the current branch
git pull origin "$(git rev-parse --abbrev-ref @)"
# Get the root directory name of the git repository (useful for directory-specific tasks)
git rev-parse --show-toplevel | xargs basename
# Delete all branches except the current one (useful for cleaning up local branches)
git branch | grep -v ^\* | xargs -I @ git branch -D @
# Switch to a branch selected with fzf (interactive fuzzy finder), allowing quick branch switching
git switch "$(git branch | fzf -1 | xargs)"
# Compare two files or directories word-by-word, without Git tracking (useful for quick diffs)
git diff --word-diff --no-index
# Show a word-by-word diff with additional output formatting (easier to parse in scripts or review)
git diff --word-diff=porcelain
Last active
November 4, 2024 02:10
-
-
Save tamakiii/b27408c8e583d29dfc8bf2067481c9fd to your computer and use it in GitHub Desktop.
Frequently used shell commands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment