Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List git repositories with unpushed changes

I'm reinstalling my OS. I have thousands of repos on my computer. I have a feeling that I've made a few changes in some repos while hacking around that are not committed and/or pushed.

From a bash shell on my Debian PC, what's the best way to find a list of changes that have not yet been committed/pushed to their remotes, and decide whether or not I want to keep the changes?

like image 994
Greg Avatar asked Mar 29 '14 19:03

Greg


3 Answers

You may like the project multi-git-status from Ferry Boender.

https://github.com/fboender/multi-git-status.
"Show uncommited, untracked and unpushed changes in multiple Git repositories."

enter image description here

like image 71
xaa Avatar answered Sep 22 '22 22:09

xaa


I'm assuming finding each repo and running git status in each repo is sufficient for your needs. In which case the following might be a starting point for you:

find / -name "*.git" -type d -print0 | xargs -0 -L 1 -i% bash -c "cd %/..; pwd; git status -s -uno"

find traverses your filesystem, starting at / (you may want to restrict that to perhaps ~), searching for .git diretories. The output (null-delimited to handle funny filenames) is piped to xargs, which cds to each repo, prints the pwd, and short-form git-status, without listing untracked files.

like image 39
Digital Trauma Avatar answered Sep 24 '22 22:09

Digital Trauma


The previous answer finds uncommitted, but not unpushed commits.

This will find both:

find / -name "*.git" -type d -print0 | xargs -0 -L 1 -i% bash -c "cd %/..; pwd; git status -s -uno; git cherry -v 2>/dev/null"

git cherry shows the SHA1 of unpushed changes; -v adds the commit comment; and error redirection suppresses noisy output for repos that lack an upstream.

like image 22
David Goldfarb Avatar answered Sep 22 '22 22:09

David Goldfarb