November 11, 2022

How to automatically update all git repos in a folder

As someone who has many github repo folders on their server I wanted an easy way to update all of them regularly with minimal points of failure so I made this script:


# store the current dir

# Let the person running the script know what's going on.
echo "\nPulling in latest changes for all repositories...\n"

# Find all git repositories and update it to the master latest revision
for i in $(find . -name ".git" | cut -c 3-); do
    echo "";
    echo ""$i"";

    # We have to go to the .git parent directory to call the pull command
    cd "$i";
    cd ..;

    # finally pull 
    # the old name
    git pull origin master;
    # the new PC friendly name
    git pull origin main;

    # lets get back to the CUR_DIR
    cd $CUR_DIR

echo "Complete!"

I have it run automatically every 10 minutes using cron

*/10 * * * * cd ~/ && bash ~/

Obviously it would be more ideal if it only ran when a repo was updated but like I said, I wanted less points of failure.

Previous post
Copilot causes popular projects to become more popular I have been using Github copilot for the past several months and I honestly think its one of
Next post
Can you afford to be an entrepreneur? With modern insurance plans how does one afford to be an entrepreneur? Asked a group of friends who are solo
Share this post if you enjoyed it :)
Subscribe to my newsletter to get notified of new posts
Follow Me On Twitter