Debug School

rakesh kumar
rakesh kumar

Posted on

shell script that will add, commit, and push each directory in the current directory:

shell-script-to-git-add-and-commit-and-push-each-directory-at-a-time

This script will loop through each directory in the repository, checking if it is a Git repository. If it is, it will add all changes in the directory, commit them with a message that includes the directory path, and push the changes to the remote repository. Note that this script assumes that the repository is structured such that each directory is a separate Git repository.

#!/bin/bash

# The root directory of the Git repository
repo_root=$(git rev-parse --show-toplevel)

# Loop through each directory in the repository
for dir in $(find "$repo_root" -type d); do
  # Navigate to the directory
  cd "$dir"
# Here's a shell script that will git add, commit, and push each directory in the repository individually:
  # Check if the directory is a Git repository
  if [ -d .git ]; then
    # Add all changes in the directory
    git add .

    # Commit the changes with a message that includes the directory path
    git commit -m "Committing changes in directory $dir"

    # Push the changes to the remote repository
    git push
  fi

  # Navigate back to the repository root
  cd "$repo_root"
done
Enter fullscreen mode Exit fullscreen mode

This script will loop through each directory in the repository, checking if it is a Git repository. If it is, it will add all changes in the directory, commit them with a message that includes the directory path, and push the changes to the remote repository. Note that this script assumes that the repository is structured such that each directory is a separate Git repository.

for dir in /; do
cd "$dir"
git add .
git commit -m "Adding changes in $dir"
git push origin master
cd ..
done
This script uses a for loop to iterate over each directory in the current directory (
/). For each directory, the script changes into the directory (cd "$dir"), adds all files (git add .), commits the changes with a message indicating which directory the changes were made in (git commit -m "Adding changes in $dir"), and pushes the changes to the remote repository on the master branch (git push origin master). Finally, the script changes back to the parent directory (cd ..) before proceeding to the next directory.

Top comments (0)