Issue
I'm finally getting used to Git and, after the initial steep learning curve, I must say it's quite good (I just miss the single file externals, but that's another story). I have, however, an issue that I can't solve: I'm currently working on a dozen projects at the same time. They are all interconnected and I must jump from one to the other, making changes here and there.
All good so far, I can "juggle" them quite easily, I commit changes regularly and so on. The issue is that, after several hours, I don't remember which projects I pushed to the remote repository. Of course, I can "cd" into each project's directory and issue the push command, but it's tedious. I was wondering if there would be a way, using bash, to run something like a git find all unpushed commits in all projects in this directory
. Such command would be run from a directory which is not a Git repository, but which contains a tree of all the projects.
The logic is simple, but the implementation seems quite complicated, also because, although the root directory contains all the projects, the actual Git repositories can be found at any level from the starting directory. For example:
- projects directory
- customer X
- project1 (Git repo)
- customer U
- project2 (Git repo)
- project3
- somelibrary (Git repo)
- theme (Git repo)
In this example, only directories in bold are Git repositories, therefore the check should be run inside them. I'm aware that the structure looks a bit messy, but it's actually quite easy to handle.
Any help is welcome, thanks.
Solution
You can find unpushed commits with git cherry
, so you should be able to write a bash script like
#!/bin/bash
for file in `find ./ -type d -maxdepth 3` ; do
cd $file
git cherry -v
cd -
done
which will find 3 layers of subdirectories, but it's probably not very nice to look at.
EDIT
As Evan suggests you can use a subshell to avoid cd
-ing back a directory, like so
#!/bin/bash
for file in `find ./ -type d -maxdepth 3` ; do
(cd $file && git cherry -v)
done
You might want to put a pwd
command in here somewhere to see which file/directory you're in...
Answered By - JKirchartz Answer Checked By - Marie Seifert (WPSolving Admin)