Skip to content

Commit

Permalink
Merge pull request #33 from jm3/multiple-remotes
Browse files Browse the repository at this point in the history
branching for repos with multiple remotes
  • Loading branch information
jamiew committed Aug 21, 2013
2 parents d766551 + 0b2e597 commit 73f0254
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions branch
Expand Up @@ -6,7 +6,6 @@
# Switch to an existing branch or creates a new local-only branch
# Adds remote tracking if a remote branch with the same name exists
# Executing without arguments prints all local & remote branches
#

remote="origin"
branch=$1
Expand All @@ -21,9 +20,16 @@ if [ -z $branch ]; then
exit 0
fi


local_branch_exists=$(git branch --no-color | egrep "$branch\$")
remote_branch_exists=$(git branch -r --no-color | egrep "$remote/$branch\$")

remotes=( $(git remote) )
for remote in "${remotes[@]}";
do
remote_branch_exists=$(git branch -r --no-color | egrep "$remote/$branch\$")
if [ "$remote_branch_exists" ] ; then
break
fi
done

# If local exists already, switch to it
if [ -n "$local_branch_exists" ] && [ ! "$local_branch_exists" == '' ]; then
Expand Down

0 comments on commit 73f0254

Please sign in to comment.