Skip to content

Instantly share code, notes, and snippets.

@svallory
Last active June 24, 2024 17:56
Show Gist options
  • Save svallory/301b8a02c6eca27a11daae8fcbecd012 to your computer and use it in GitHub Desktop.
Save svallory/301b8a02c6eca27a11daae8fcbecd012 to your computer and use it in GitHub Desktop.
Supercharged Git and Github Aliases for ZSH
#!/bin/zsh
###########################################################
# Get URLs for the current branch or the main branch
# Adding a path after the command will show the URL of that file on the current branch and the main branch
#
# NOTE: this DOES NOT CHECK if the file exists on github
#----------------------------------------------------------
# Examples:
# ```bash
# $> ?url
# https://github.com/[user]/[repo]/tree/[branch]
#
# $> ?url PATH
# https://github.com/[user]/[repo]/blob/[branch]/[PATH]
#----------------------------------------------------------
alias \?url='gh browse -n -b `?branch`'
alias \?url@main='gh browse -n'
###########################################################
# Most Common Commands
# ---------------------------------------------------------
alias c='git commit -m'
alias clone='gh repo clone'
alias nuke='git reset --hard'
alias pull='git pull'
alias push='git push'
alias publish='git push --set-upstream origin $(?branch); open-pr'
# Tools
# ---------------------------------------------------------
alias lg='lazygit'
alias gl='git log --oneline --graph --decorate --all'
# Getting Info
# ---------------------------------------------------------
alias \?='git status'
alias \?branch="git branch --show-current"
alias \?remote="git remote"
alias \?repo='git remote get-url `?remote`'
alias \?pr='gh pr view --json url --jq .url'
alias \?has-pr='if gh pr view --json url > /dev/null; then echo "yes"; else echo "no"; fi'
# Automations
# ---------------------------------------------------------
alias push-open='git push; open-pr'
alias pr-auto-title='?branch | sed -e "s/\//: /" -e "s/-/ /g"'
alias open-pr='TITLE="$(pr-auto-title)" && \
echo -e "\e[0;90mAuto Title:\n\e[1;34m$TITLE\e[0m" && \
gh pr create -a @me -t "$TITLE" -B staging';
# Cheating
# ---------------------------------------------------------
alias push-🙈='git push --no-verify';
alias push-open-🙈='git push --no-verify; open-pr';
alias publish-🙈='git push --set-upstream origin $(?branch) --no-verify; open-pr';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment