简体   繁体   中英

Pull the latest changes from git for a specifc repository

I have written an automated script using vsts personal access token to clone all the repositories in a project to my local. The script is

repoPaths=('repo1Url','repo2Url',etc...)
for i in "${repoPaths[@]}"
do
     git clone $repPaths[i] $localPath
done

Now, I'm trying to make some changes in the above bash script to pull the latest changes if the clone is available from all of the repo's .

Please suggest.

You could have 2 steps, one to pull all repos in x directory and one to clone all repos in x directory. Something like this should suffice:

find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;

So combined, it'd be:

find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;
repoPaths=('repo1Url','repo2Url',etc...)
for i in "${repoPaths[@]}"
do
     git clone $repPaths[i] $localPath
done

Note: This will result in some errors that look like fatal: destination path 'repo1Url' already exists and is not an empty directory. if it already exists

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM