Skip to content

Instantly share code, notes, and snippets.

@nucliweb
Last active December 27, 2022 14:58
Show Gist options
  • Save nucliweb/c2163e31029255d068eb to your computer and use it in GitHub Desktop.
Save nucliweb/c2163e31029255d068eb to your computer and use it in GitHub Desktop.
Run pull origin master over all subdirectories

Update all the repositories in a folder (Mac OS X & Linux)

This command updates the repositories in all subfolders inside a folder.

⚠️ The script updates the current banch in each folder.

For e.g. run in code folder to update respositories in all the subfolders

/code
 |
 +-- /joaneleon.dev
 |
 +-- /nucliweb.net
 |
 +-- /webperfimpacters.com

As command

Run the next line in your terminal to update all the repositories inside a folder.

find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull --set-upstream origin HEAD \;

As Bash Script

Create a Bash Script file, e.g. ~/git-pull-subfolders.sh, with the next code:

#!/usr/bin/env bash

find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull --set-upstream origin HEAD \;

Add execute permission to the file with the next command:

chmod +x ~/git-pull-subfolders.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment