#!/bin/bash

Dir=$1

ForkName=$2

cd $Dir

current_branch=$(git branch | awk '$1 == “*”{print $2}')

stash_result=$(git stash | grep “No local changes to save”)

if [[ “$stash_result” != “” ]] then

echo "No local changes to save."

else

echo "Saved working directory and index state WIP on ${current_branch}."

fi

echo “Switch master branch.”

git checkout -f master

result=$(git remote -v | grep $ForkName)

echo “Update master branch.”

if [[ “$result” != “” ]] then

git fetch $ForkName master

git merge $ForkName/master

else

git fetch origin master

git merge origin/master

fi

if [[ “$current_branch” != “master” ]] then

echo "Switch ${current_branch} branch."

git checkout $current_branch

echo "Update ${current_branch} branch."

git rebase master

fi

if [[ “$stash_result” == “” ]] then

echo "Restore {current_branch} status."
log=$(git stash pop)

fi

cd ..