1
0

post-checkout 525 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env bash
  2. # ignore detached heads
  3. if ! git symbolic-ref -q HEAD > /dev/null; then
  4. exit
  5. fi
  6. # ignore non-branch checkouts
  7. if [[ "$3" != "1" ]]; then
  8. exit
  9. fi
  10. # skip if upstream is already set
  11. if git rev-parse --verify --quiet '@{u}' > /dev/null 2>&1; then
  12. exit
  13. fi
  14. # use upstream/HEAD if it exists, otherwise origin/HEAD
  15. if git show-ref --verify --quiet refs/remotes/upstream/HEAD; then
  16. git branch --set-upstream-to refs/remotes/upstream/HEAD
  17. else
  18. git branch --set-upstream-to refs/remotes/origin/HEAD
  19. fi