Skip to content

Instantly share code, notes, and snippets.

@graysky
Forked from sstephenson/git-track
Created November 25, 2008 20:41
Show Gist options
  • Save graysky/29079 to your computer and use it in GitHub Desktop.
Save graysky/29079 to your computer and use it in GitHub Desktop.
Auto-track a git branch
#!/bin/sh
# Sets up auto-tracking of a remote branch with same base name.
# Can set up "git track" so it feels built-in:
# git config --global --add alias.track '!git-track'
#
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment