Update All Repos Bash Script
Utility script to update all repos wihtin a directory.
1 Minute, 10 Seconds
2024-07-13 00:00 +0000
Update Repositories Script
This script recursively finds all git repositories in a specified directory and pulls the latest changes for each one.
Prerequisites
- Bash shell
- Git installed
- Proper permissions to access and modify the repositories
Installation
Create the script: Save the following script to a file named
update_repos.sh
:#!/bin/bash # Define the default root directory where your repos are located DEFAULT_ROOT_DIR="/home/cobra/Repos" # Use the provided argument as the root directory, or the default if none is provided ROOT_DIR=${1:-$DEFAULT_ROOT_DIR} echo "Starting update process for repositories in $ROOT_DIR" # Function to pull changes in a git repository pull_repo() { local repo_dir=$1 echo "Pulling updates in $repo_dir" cd "$repo_dir" || return git pull echo "Completed update in $repo_dir" cd - || return } # Export the function so it can be used by find -exec export -f pull_repo # Find all .git directories and pull changes in their parent directories find "$ROOT_DIR" -name ".git" -type d -exec bash -c 'pull_repo "$(dirname "{}")"' \; echo "All repositories updated."
Make the script executable:
chmod +x update_repos.sh
Move the script to
/usr/local/bin
:sudo mv update_repos.sh /usr/local/bin/update_repos
Verify the script is accessible: You can now run the script from anywhere by simply typing
update_repos
in the terminal.
Usage
Open a terminal.
Run the script by typing:
update_repos [path_to_repos]
- If no path is provided, it defaults to
/home/cobra/Repos
.
- If no path is provided, it defaults to
The script will find all .git
directories in the specified root directory and pull the latest changes for each repository. It will provide status updates during the process.
License
This project is licensed under the MIT License.