Home > Back-end >  How can I keep the local copy of all my GitHub repositories updated?
How can I keep the local copy of all my GitHub repositories updated?

Time:11-14

I have all the GitHub repositories that I work on in a local folder in my computer in this way:

all_repos/
├── repo_1
├── repo_2
├── repo_3
├── ...
├── repo_n

How can I keep them all updated with the version on GitHub automatically?

CodePudding user response:

This can be solved very simply with this bash script:

#!/bin/bash

for d in *; do
    if [[ -d "$d/.git" ]]; then
        pushd "$d"
        git fetch
        popd
    fi
done

CodePudding user response:

Just add this Python pull_all.py script to that folder:

all_repos/
├── pull_all.py
├── repo_1
├── repo_2
├── repo_3
├── ...
├── repo_n

And inside the script pull_all.py:

import os
import subprocess

folder = os.path.dirname(os.path.realpath(__file__))
subfolders = [ f.path for f in os.scandir(folder) if f.is_dir() ]

for subfolder in subfolders:
    print(f"Updating {subfolder}")
    os.system(f"cd {subfolder}; git fetch")

Just run the script from inside the all_repos folder with:

python pull_all.py

to update all repositories.

  • Related