I’ve written a script to update my git repos automatically.
It worked until I added a check as to whether the current branch was the main
branch.
At this point, the script bombs out on the line of the if
guards saying:
[[main: command not found
The script is:
#!/bin/bash
api='/C/Repos/me/services/api'
declare -a reposArray=($api)
for repo in "${reposArray[@]}"
do
echo
echo "updating $repo"
cd $repo
echo "fetching code"
#git fetch --prune
branch="$(git branch --show-current)"
if [["$branch" != "main"]]; then
git switch main
fi
echo "merging remote into main"
git merge
done
Any idea what is wrong?
Does main
have a special meaning such that it needs to be escaped?
How would I escape a whole word like that?
Cheers