Skip to content

Instantly share code, notes, and snippets.

@kipras
Forked from sstephenson/git-track
Created October 20, 2013 14:59
Show Gist options
  • Save kipras/7070714 to your computer and use it in GitHub Desktop.
Save kipras/7070714 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# From: http://graysky.org/2008/12/git-branch-auto-tracking/
#
# git-track should be added to your path.
# 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'
#
# Update: changed the way current branch name is determined, see:
# http://git-blame.blogspot.com/2013/06/checking-current-branch-programatically.html
# Also made sure that when not on any branch (in detached head state) - that track would
# not do anything
if tracking=$(git symbolic-ref --short -q HEAD)
then
git config branch.$tracking.remote origin
git config branch.$tracking.merge refs/heads/$tracking
echo "tracking origin/$tracking"
else
echo not on any branch
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment