Last active
November 16, 2023 10:21
-
-
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
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
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is imperfect, but good enuf for my use cases :)