/gcom
Created
May 4, 2025 06:22
Revisions
-
f4th4n created this gist
May 4, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/bin/bash # This script checks if the 'main' branch exists in the current Git repository. # If 'main' exists, it checks out the 'main' branch. # If 'main' does not exist, it checks out the 'master' branch. # Check if the 'main' branch exists # git rev-parse --verify <branch_name> returns 0 if the branch exists, non-zero otherwise. if git rev-parse --verify main >/dev/null 2>&1; then echo "Branch 'main' exists. Checking out 'main'..." git checkout main if [ $? -eq 0 ]; then echo "Successfully checked out 'main'." else echo "Error checking out 'main'." exit 1 fi else # If 'main' does not exist, check out 'master' echo "Branch 'main' does not exist. Checking out 'master'..." # Check if 'master' branch exists before attempting to checkout if git rev-parse --verify master >/dev/null 2>&1; then git checkout master if [ $? -eq 0 ]; then echo "Successfully checked out 'master'." else echo "Error checking out 'master'." exit 1 fi else echo "Neither 'main' nor 'master' branches exist in this repository." exit 1 fi fi exit 0