Skip to content

Instantly share code, notes, and snippets.

@keenahn
Last active November 16, 2023 10:21
Show Gist options
  • Save keenahn/7772d481d4e0502727266f2429984488 to your computer and use it in GitHub Desktop.
Save keenahn/7772d481d4e0502727266f2429984488 to your computer and use it in GitHub Desktop.
A simple bash script to check if the default branch is main or master for a given repo
#!/bin/bash
# Check if the remote 'origin' has a 'main' branch
if git show-branch remotes/origin/main > /dev/null 2>&1; then
echo "main"
else
echo "master"
fi
# 1. Save this file somewhere in your $PATH
# 2. Add to your ~/.gitconfig the following
#
# [alias]
# default-branch = !"git-default-branch.sh"
@keenahn
Copy link
Author

keenahn commented Mar 31, 2023

It is imperfect, but good enuf for my use cases :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment