1234567891011121314151617181920212223 |
- #!/usr/bin/env bash
- # ignore detached heads
- if ! git symbolic-ref -q HEAD > /dev/null; then
- exit
- fi
- # ignore non-branch checkouts
- if [[ "$3" != "1" ]]; then
- exit
- fi
- # skip if upstream is already set
- if git rev-parse --verify --quiet '@{u}' > /dev/null 2>&1; then
- exit
- fi
- # use upstream/HEAD if it exists, otherwise origin/HEAD
- if git show-ref --verify --quiet refs/remotes/upstream/HEAD; then
- git branch --set-upstream-to refs/remotes/upstream/HEAD
- else
- git branch --set-upstream-to refs/remotes/origin/HEAD
- fi
|