Last active
October 2, 2024 19:57
-
-
Save amingilani/cce71595e7fc0b45d0d93f86042ab286 to your computer and use it in GitHub Desktop.
Convenient Git and GitHub functions in my .zshrc
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
# Copy thes to your .zshrc or .bashrc | |
# Rebase main/master onto my current branch | |
bup(){ | |
branch="main" | |
if git show-ref --quiet refs/heads/master; then | |
branch="master" | |
fi | |
git fetch origin "${branch}":"${branch}" && \ | |
git rebase "${branch}" && \ | |
git push --force-with-lease | |
} | |
# Update PR title and description from last commit | |
dub (){ | |
# Allows adding markdown directly within | |
# the commit message and have it be used as the PR body in GitHub. | |
# This enables using GFM features like diagrams, tables, codeblocks, etc. | |
# | |
# Pre-requisites: | |
# - gh cli: https://cli.github.com/ | |
# - Use `;` (instead of `#`) as the comment character in Git to allow | |
# Python # comments in code blocks. Just run the following | |
# command in your terminal: git config --global core.commentChar ";" | |
# Get the commit title | |
title=$(git log -1 --pretty=format:%s) | |
# Get the commit body and skip the first four lines | |
body=$(git log -1 --pretty=format:%B | awk 'NR>2') | |
# Combine the title and body | |
combined_body="# $title\n\n$body" | |
# Update the PR title | |
echo "$title" | xargs -I{} gh pr edit --title "{}" | |
# Update the PR body | |
echo -e "$combined_body" | gh pr edit --body-file - | |
} | |
# View branch on GitHub | |
bv (){ | |
branch="$(git symbolic-ref --short HEAD)" | |
gh browse --branch "${branch}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment