How to Batch Pull Git Repository Updates
When there are many repositories, it can become tedious to manually pull each one. By using the method described in this article, you can perform batch pull operations on Git repositories.
Steps
- Create a script file named
pull-master.sh
and paste the following code into it:
pull-master.sh
#!/bin/bash
function showMsg()
{
echo -e "\033[32m$1\033[0m"
}
function getdir(){
for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
cd $1"/"$element
showMsg 'git pull '$element
git pull
else
echo $dir_or_file
fi
done
}
root_dir="[to_be_replace[Path containing multiple repositories]]"
getdir $root_dir
- Replace
[to_be_replace[Path containing multiple repositories]]
with your own path, for example,C:\repos
. - Run the command:
or double-click pull-master.sh
to run it.
Scheduled Execution
- Search for and open
Task Scheduler
. - Click
Create Task
.- Fill in the name on the
General
tab. - Set the schedule on the
Triggers
tab. - Create a new action on the
Actions
tab, fill in theProgram/script
(e.g.,F:\pull-master.sh
), add arguments (e.g.,pull-master.sh
), and start in (e.g.,F:\
).
- Fill in the name on the
- Test run the task. If there are no issues, it should work. (If it doesn't work, you can refer to Pull-Git-Repo.xml)
Deployment on Synology NAS
- Place the script (e.g.,
github-pull.sh
) in any path on the NAS. - Modify the path of
root_dir
ingithub-pull.sh
, for example, change it to"/volume1/projects"
, which is where you store your Git repositories. - Go to
Control Panel
-Task Scheduler
-Create
-Scheduled Task
-User-defined script
. Configure the schedule and command to run the script (e.g.,bash /volume1/stash/permanent/github-pull.sh
). - In
Settings
, configure the output result. Then select the task, clickRun
to test the execution, and open the configured output path to view the results.
If you are prompted to enter a password every time, you can enter the following command (user home directory needs to be enabled in advance):
This will generate a text file locally that stores the account and password.
The next time you are prompted for a password, you only need to enter it once and you won't need to enter it again in the future.
References and Acknowledgements
This post is translated using ChatGPT, please feedback if any omissions.