Skip to content

Instantly share code, notes, and snippets.

@webdevel
Last active December 5, 2021 14:27
Show Gist options
  • Save webdevel/5126749 to your computer and use it in GitHub Desktop.
Save webdevel/5126749 to your computer and use it in GitHub Desktop.
GetOpts Example

GetOpts Example

Shell script example of using GetOpts with Git Submodule.

#!/bin/sh

REMOTE=origin
BRANCH=dev

showHelp()
{
cat << EOF

Pull in the latest changes from remote branch.

Usage: $(basename $0) [OPTIONS]

OPTIONS:
  -h    Show this help message
  -b    Branch name (default: $BRANCH)
  -r    Remote alias (default: $REMOTE)

EOF
}

while getopts "hr:b:" option; do
    case $option in
        r)
            REMOTE=$OPTARG
            ;;
        b)
            BRANCH=$OPTARG
            ;;
        h)
            showHelp
            exit
            ;;
    esac
done

git pull $REMOTE $BRANCH
git submodule foreach git pull $REMOTE $BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment