Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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

makavelilcf commented Sep 27, 2012

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