|  | @@ -0,0 +1,18 @@
 | 
	
		
			
				|  |  | +#!/usr/bin/env bash
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# 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
 |