Skip to content

Instantly share code, notes, and snippets.

@WillianTomaz
Last active June 8, 2023 13:58
Show Gist options
  • Save WillianTomaz/6b64d840323a3e2bba634c304100d0c6 to your computer and use it in GitHub Desktop.
Save WillianTomaz/6b64d840323a3e2bba634c304100d0c6 to your computer and use it in GitHub Desktop.
Script para manter repositórios locais atualizados.

Thursday, June 8, 2023

Script to keep local repositories up to date

  • Note:

    • Basically this script would run in your root folder of your repositories which contains all your repositories and do a git pull on all of them.
    • For better functioning, use SSH when cloning your repositories. So you don't need to enter a password at the time of git pull.


Step By Step:

1. Creating the file:

nano git-pull-all-repos.sh

2. Adding permissions to the file:

sudo chmod 777 git-pull-all-repos.sh

3. Now let's copy the script below and put it inside the git-pull-all-repos.sh file we created in the previous step:

#!/bin/bash

# Getting absolute path to file
SCRIPT=$(readlink -f "$0")

# Getting only the absolute path (without the file name in the path)
SCRIPTPATH=$(dirname "$SCRIPT")

# Showing the path where it contains the repositories
echo "PATH: $SCRIPTPATH"

# Looping over the command "ls -d */". It will return a list of directories.
for OUTPUT in $(ls -d */)
do
    echo "--------------------------"
    echo "REPOSITORY: $OUTPUT"
    cd $SCRIPTPATH/$OUTPUT
    git pull
    cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment