Created
November 20, 2024 07:33
-
-
Save timbaileyjones/bb063f0e0ddcbd54fffa92e6c817dc95 to your computer and use it in GitHub Desktop.
Quick script to help you keep track of any uncommitted or unpush changes to ANY repo on your workstation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for REPO in $( find ~/[A-Za-z]* -type d -depth 2 -name .git ) | |
do | |
cd "${REPO}"/.. | |
if [ ! -z "$(git status --porcelain)" >/dev/null ] | |
then | |
echo ${PWD} ------------ | |
git status --porcelain | |
echo | |
if [ ! -z "${*}" ]; | |
then | |
echo "running ${*} within ${PWD}... type 'exit' to continue, if this command is interactive..." | |
${*} | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a classic "I scratched my itch, hope it helps" story.
I sometimes lose track of unpushed/uncommitted changes, across multiple projects / clients. To get a handle on this, I wrote this script called
git-dirty
and put it at/usr/local/bin
, with execute permissions. Feel free to change the argument afterfind
to match where you keep your code projects. This version starts with your $HOME directory. If you mostly work withgolang
, you might set it to$HOME/go/src
, or if you work at Amazon, you might find$HOME/workplace/[A-Za-z]*/.
useful.It finds all your git repos under your home directory. For each repo it:
git status --procelain
, and ...So you could use this script in combination with other commands to do some useful stuff:
git-dirty
-- just show what you have that isn't committed, no action taken.git-dirty git pull
-- make sure you have the latest for each repo. I keep forgetting to git-pull after merging CRs in the web console.git-dirty git reset --hard
-- reset each repo back to whatever the latest local commit is.git-dirty git clean
-- remove untracked files from the working tree.git-dirty zsh
-- spawn into a shell into each "dirty" directory, where you can take any action you want interactively (i.e.git diff
,git reset
, make edits, commit/push your changes, or even use the Github CLI to create a PR. Just typeexit
from that shell, andgit-dirty
will find the next repo with uncommitted or unpushed changes, if any.Comments welcome...