Skip to content

Instantly share code, notes, and snippets.

@bossjones
Forked from graysky/git-track
Created July 14, 2019 01:01
Show Gist options
  • Save bossjones/0dbc04d0bd54190c0205c6aa9ce6d383 to your computer and use it in GitHub Desktop.
Save bossjones/0dbc04d0bd54190c0205c6aa9ce6d383 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