I know this isn't recommended, but I do have folders with multiple projects that I like to keep up to date.
Is there a command that will look for each git repository in a folder and send the following commands..
git add -u
git add .
git commit -m 'Latest'
So I could just cd into some folder, then run a command that gets them all updated?
This is not a submodules question
With Git, using multiple repositories is the only way to work efficiently. This enables each team to work independently, and do their work faster. You can also make sure that developers only have access to the repositories they need access to (thus making Git more secure.)
To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.
You can add multiple remotes by using git remote or git config commands or editing the config file.
I use a bash script (in my .bashrc
) to run multiple time the same git command on several repos.
The bash hardcodes the repo location but it could easily be changed. One of the issues with running multiple times the same command is correctly passing the quoted "
arguments, typically -m " commit message"
I run those command like this:
mgit commit -a -m "my commit message"
where mgit is a alias in my .bashrc.
This works for any git commant (I least the one I tested and used on a daily basis), eg:
mgit status -uno
, mgit pull
This function ensure any quoted argument (after the -m
are correctly handled)
parse_git_args()
{
git_args=""
end_comment=""
for var in "$@"
do
if [[ $var == '-m' ]];
then
git_args+=" -m \""
end_comment="\""
else
git_args+=" $var"
fi
done
git_args+=$end_comment
echo $git_args
}
multiple_git_func()
{
start=$(pwd)
git_args=$(parse_git_args $@)
root=`git rev-parse --show-toplevel` #find the repo from which the command was run
# go to root apply command and then go to sub repos (hardcoded location wrt root)
cd $root
echo "=============================="
echo "issuing git $git_args on $root"
eval "git $git_args"
cd repo2 # repo2 is installed in root, could be anywhere else relative to root
echo "=============================="
echo "issuing git $git_args on repo2"
eval "git $git_args"
#go back to initial folder
cd $start
}
alias mgit=multiple_git_func
why don't you use something like this:
#!/bin/bash
for DIR in `ls`;
do
if [ -d $DIR/.git ];
then
echo "updating location: " $DIR;
cd $DIR
# your commands here...
git add -u
git add .
git commit -m 'Latest'
cd ..
fi
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With