Let's say I've got the following directory structure.
.ProjectFolder
|-A
|-B
|-C
Where A,B and C are all github projects.
I could do
git submodule foreach git checkout <branch> && git submodule foreach git pull
to checkout and pull each one to the most recent version of . However, let's say that I have some work done on A locally, and git will tell me that it cannot check out to because of my uncommited work.
I would like to write a bash script that goes inside of each folder, checks out said branch if possible, then performs a set of actions. Say
for item in $(ls);do
cd ./$item
git checkout <branch>
git pull
cd ..
done
The issue with that is "cd". When I try doing that, it doesn't seem to go into the folder. I've browsed a bit around and I've seen that happens because "cd" runs a subshell, then exits, leaving me in the same place as before. I've tried sourcing the file rather than running it, and that didn't seem to work either.
Does anybody have any alternative? (preferably, alternatives that don't use aliases for "cd").
The reason why i'd like to do it this way is because I'd like to extend that functionality at some point I.E. checkout to a new local branch, commit the changes to that branch, then attempt to checkout the branch I was interested in.
I've seen that happens because "cd" runs a subshellthis is not true - please update the question to show the error message you are seeing or more precisely describe the problem.cdin a subshell that subsequently exits, not thatcdspawns a subshell.