Some useful Bash Scripts

A curated list of bash scripts to automate a few stuff to make my life (or could be yours) easy.

Update local GIT repositories

A bash script that iterates through directories and runs git pull in those that are Git repositories:

# Loop through each directory in the current directory
for dir in ./*; do
  # Check if it's a directory (avoid hidden files)
  if [[ -d "$dir" && ! "$dir" == .git ]]; then
    # Change directory to the current one
    pushd "$dir" >/dev/null 2>&1

    # Check if it's a Git repository (presence of .git directory)
    if [[ -d .git ]]; then
      echo "Updating $dir..."
      # Pull changes from remote repository
      git pull

    # Move back to the previous directory
    popd >/dev/null 2>&1

Last updated on: 2024-04-14