I'm trying to write a bash script called by a daily cron schedule that will cycle all sub directories looking for a .git directory, run a git pull --all
on that repository to update the repo and grab any new branches, track those branches, and then move on to the next repo. I'm a bash script beginner and familiar with some linux. My problem is the for loop which I found at How to clone all remote branches in Git? but doesn't seem to run properly now that I've introduced it into my script and the call to cd ${line}..
which doesn't seem to work as anticipated. I'm wondering what i've done wrong and some direction on how to fix it. Thank You.
My current script gitcron.sh:
#!/bin/bash
find . -maxdepth 2 -name .git -type d -print > .gitrepos
while read -r line; do
cd ${line}/..
git pull --all
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
done
done < ".gitrepos"
.gitrepos generated file:
./codeigniter/.git
./magento/.git
./magento2/.git
My problem:
gitcron.sh: line 6: cd: ./magento2/.git/..: No such file or directory
fatal: it does not make sense to create 'HEAD' manually
error: unknown switch `>'