Last active
October 13, 2023 11:00
-
-
Save mertant/3d5e77fee7ed72573ccd29b76437b2b6 to your computer and use it in GitHub Desktop.
This file contains 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
#### Git command aliases | |
# | |
# Add to your .zshrc or other terminal config file | |
# | |
## Frequently used commands: | |
alias gis="git status" | |
alias gif="git fetch" | |
alias girbom="git rebase origin/master" | |
alias girbomn="git rebase origin/main" | |
## Force-with-lease: | |
alias gipfwl="git push --force-with-lease" | |
# Use for safer force pushing (e.g. after rebase). Does nothing if remote is not in the state we expected. | |
# See https://blog.developer.atlassian.com/force-with-lease/ | |
## Interactive rebase: | |
function girbi() { | |
git rebase --interactive HEAD~$1 | |
} | |
# Use to squash or reword commits on the current branch. | |
# For example, to squash or reword the last 4 commits: | |
# 'git rebase --interactive HEAD~4' | |
# or using the alias: | |
# 'girbi 4' | |
# | |
# Note that the number is inclusive of the HEAD commit. | |
# To make it easy to count the commits, use a oneline log format such as | |
# 'git log --pretty=oneline --abbrev-commit' | |
# | |
## Copy branch name: | |
alias gicb="git rev-parse --abbrev-ref HEAD | tee >(pbcopy); echo '[Copied branch name to clipboard.] ';" | |
## Commit history/git log | |
# Custom log format that's sorta like --oneline but reordered and padded, and also includes date information. | |
# usage: --pretty=format:$mygitformat OR --format=$mygitformat | |
# format contains: abbreviated_hash | message | short_date ~ relative_date | (tags) | | |
export mygitformat='%C(auto)%h%C(reset) | %<(80,trunc)%C(auto)%s%C(reset) | %C(auto)%cs%C(reset) ~ %<(12,trunc)%C(auto)%cr%C(reset) | %<(40,trunc)%C(auto)%d%C(reset) |' | |
# --no-pager ensures that it's printed into terminal, not opened in a new 'less' process. (While also preserving color, unlike cat/head tend to do) | |
# Log recent commits in current branch/all branches: | |
alias gil='git --no-pager log --first-parent --format=$mygitformat -n 20' | |
alias gila='git --no-pager log --first-parent --all --format=$mygitformat -n 20' | |
# Check recent _merge commits only_ into master branch: | |
function gilm() { | |
default_branch='origin/master'; # Or replace with origin/main | |
n_lines=$1; | |
if [ -z "$1" ] # Default when no args | |
then | |
n_lines=10; | |
#else | |
#n_lines=$1; | |
fi | |
echo "[$0()] Printing last $n_lines merges into branch $default_branch" | |
git --no-pager log $default_branch --first-parent --show-pulls --format=$mygitformat -n $n_lines | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment