Skip to content

Instantly share code, notes, and snippets.

@sstephenson
Created November 25, 2008 20:19
Show Gist options
  • Save sstephenson/29070 to your computer and use it in GitHub Desktop.
Save sstephenson/29070 to your computer and use it in GitHub Desktop.
#!/bin/sh
branch=$(git branch 2>/dev/null | grep ^\*)
[ x$1 != x ] && tracking=$1 || tracking=${branch/* /}
git config branch.$tracking.remote origin
git config branch.$tracking.merge refs/heads/$tracking
echo "tracking origin/$tracking"
@crfilho
Copy link

crfilho commented Jul 13, 2011

GREAT

@makavelilcf
Copy link

Hi!

I got the problems on the colored shell, that's why made some modifications to your script:

!/bin/sh

If argument is provided

if [ banana$1 != banana ]; then
tracking=$1

Get it from current branch

else
branch=$(git branch 2>/dev/null | grep ^* | awk '{print $2}')
echo "Current branch: "$branch
tracking=$branch
fi

git config branch.$tracking.remote origin
git config branch.$tracking.merge refs/heads/$tracking

echo "tracking origin/$tracking"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment