Skip to content

Instantly share code, notes, and snippets.

@larouxn
Last active February 20, 2026 15:33
Show Gist options
  • Select an option

  • Save larouxn/3bc34f8952b5753461a023e89d63e12c to your computer and use it in GitHub Desktop.

Select an option

Save larouxn/3bc34f8952b5753461a023e89d63e12c to your computer and use it in GitHub Desktop.
🚢 rebasecity branch_name 🚀
#           _                         _ _         
#          | |                       (_) |        
#  _ __ ___| |__   __ _ ___  ___  ___ _| |_ _   _ 
# | '__/ _ \ '_ \ / _` / __|/ _ \/ __| | __| | | |
# | | |  __/ |_) | (_| \__ \  __/ (__| | |_| |_| |
# |_|  \___|_.__/ \__,_|___/\___|\___|_|\__|\__, |
#                                            __/ |
#                                           |___/ 
#
# ascii art thanks tro https://calligraphy.geopjr.dev/
#
# Rebase whatever branch you like against your latest primary branch.
# Use: rebasecity branch_name
#
# Helper function to dynamically detect the primary branch
_git_default_branch() {
# Check if 'main' exists locally or on the remote
if git rev-parse --verify --quiet refs/heads/main >/dev/null || \
git rev-parse --verify --quiet refs/remotes/origin/main >/dev/null; then
echo "main"
else
echo "master"
fi
}
# Fetch primary, checkout target, rebase, and force push
rebasecity() {
local primary=$(_git_default_branch)
git fetch origin "$primary" && \
git checkout "$@" && \
git rebase "origin/$primary" && \
git push origin --force-with-lease "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment