Pushing Multiple Git Repos
I am currently TAing the class AM 129: Foundations of Scientific Computing and I need to grade code located in the student’s git repo. Thus I came up with this script to add, commit, and push the students’ grade all at once. This has saved me plenty of time!
# Asks to enter a commit message
# in my situation its usually something like "homework x grade"
echo 'Enter the commit message:';
read commitMessage;
# This loop finds directories/git repos in the current directory
for d in */ ; do
# Then changes directory the git repo and adds, commits, and pushes, then changes back to top directory
cd ./$d
git pull
git add -A
git commit -m "$commitMessage"
git push
cd ../
done
This can be easily modified if you have a specific branch that this needs to be pushed to. You would need to add
echo Enter branch name:
read branchName
to after the commit message prompt. Then modify the git push
to git push origin $branchName
.