I'm trying to find a way to rebase the repository by using a Bash Script, I got this, but it returned alot a few errors that I don't know how to fix them for example: ./bash.sh: line 3: $'\r': command not found
Errors:
./bash.sh: line 3: $'\r': command not found
./bash.sh: line 6: $'\r': command not found
Updating Repo: /home/teste/ with url:
./bash.sh: line 8: $'\r': command not found
./bash.sh: line 16: syntax error near unexpected token `$'\r''
'/bash.sh: line 16: `(git fetch --all && git stash)
Here is the script that I got
directory="/home/teste/" ## Where the server is located
original_dir="/root" ## Where we should back after the pull
cd $directory # switch to the git repo
repo_url=$(git config --get remote.origin.url)
echo "Updating Repo: $directory with url: $repo_url"
main_branch="master"
if [ "$repo_url" == "XXXXX" ]; then # if you have a repo where the primary branch isnt master
$main_branch="trunk"
fi
# update the repo, then stash any local changes
echo -e "\ncalling: git fetch --all && git stash"
(git fetch --all && git stash)
current_branch=$(git rev-parse --abbrev-ref HEAD)
# switch to master/trunk branch and rebase it, then switch back to original branch
if [ $current_branch != $main_branch ]; then
echo -e "\ncalling: git checkout $main_branch && git rebase && git checkout $current_branch"
(git checkout $main_branch && git rebase && git checkout $current_branch)
fi
# rebase the original branch and then stash pop back to original state
echo -e "\ncalling: git rebase && git stash pop on branch: $current_branch"
(git rebase && git stash pop )
#switch back to the starting directory
cd $original_dir
echo ""