check_git_status.sh
is a Bash script designed to verify the status of multiple Git repositories within a workspace. It helps identify untracked files, unstaged changes, uncommitted commits, and branch differences with the remote repository.
The script analyzes each Git repository in a workspace and identifies:
-
Untracked files:
- Files in the working directory that haven’t been added to Git (
git add
not run).
- Files in the working directory that haven’t been added to Git (
-
Staged but uncommitted files:
- Files that were added with
git add
but not yet committed.
- Files that were added with
-
Unstaged changes:
- Files with local modifications that haven’t been added to the staging area.
-
Unpushed commits:
- Local commits that haven’t been pushed to the remote repository.
-
Branches not in sync with the remote (only when using the
fetch
option):- Detects if the local branch is ahead of or behind the remote branch.
The script supports the following modes:
-
Default Mode: Checks repository status without updating remote references.
check_git_status
-
Fetch Mode: Runs
git fetch
for each repository before performing checks.check_git_status fetch
-
Debug Mode: Outputs detailed information during execution, useful for troubleshooting.
check_git_status debug
-
Fetch + Debug Mode: Combines
fetch
anddebug
modes, updating remote references and providing detailed output.check_git_status fetch-debug
-
Specifying Directories: You can also pass specific directories as arguments to limit the scope of the search for Git repositories. The script will recursively explore those directories for any repositories. If no directories are specified, it defaults to searching the current directory.
check_git_status /path/to/workspace1 /path/to/workspace2
or
check_git_status fetch /path/to/workspace1 /path/to/workspace2
The script generates a summary table listing the repositories with detected changes. Example:
The script generates a summary table listing the repositories with detected changes. Example:
Package Name | Status | Behind Origin | Repository Path |
---|---|---|---|
example_repo | Modified but not added/committed | No | /path/to/workspace/example_repo |
another_repo | Branch not in sync with remote | Yes | /path/to/workspace/another_repo |
Status
: Indicates the repository's local changes.Behind Origin
: Shows whether the local branch is behind the remote (only visible iffetch
is used).Repository Path
: Displays the full directory path of the repository.
If no issues are detected, the script outputs:
All repositories are up-to-date.
-
Copy the scripts to a directory in your PATH:
- To see directories in your PATH, run:
echo $PATH
- Common directories include
/usr/local/bin
. Copy the script there:sudo cp check_git_status.sh /usr/local/bin/
- Copy the autocompletion script:
sudo cp check_git_status /etc/bash_completion.d/
- To see directories in your PATH, run:
-
Grant Execute Permissions:
sudo chmod +x /usr/local/bin/check_git_status.sh sudo chmod +x /etc/bash_completion.d/check_git_status
-
Verify Installation: You should now be able to run the script from any directory:
check_git_status
- Git: Ensure Git is installed on your system.
- Bash: The script is compatible with Bash.
If you have suggestions to improve the script or encounter any issues, feel free to submit a pull request or report a problem.
- Without the
fetch
option, the script does not detect changes in branches that are not synced with the remote. - If you pass directories as arguments, the script will search those specific directories and their subdirectories for Git repositories. If no directories are passed, the script will search the current directory by default.