Shell script automatically corrects git project url

need

After the server modified the group of the git project, all git addresses under the group changed, causing the local git to be unable to update/submit the code normally.
An error occurs after executing git pull

GitLab: Project 'old/project' was moved to 'new/project'.

Please update your Git remote and try again:

  git remote set-url origin ssh://xxxxx/new/project.git
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

For example, the Android project is managed using repo, and each directory is managed with a sub-git. There will be about 30 gits in total. Remote modification of the group will affect all gits, and it is troublesome to modify each one manually
.

It’s much easier to fix it with a script

accomplish

pullall.sh, this script traverses all git projects in the current directory and executes the git pull command. If an error is detected and is caused by a change in the URL, the git remote set-url xxx command will be automatically executed to repair it. After the repair is completed, execute git again
. pull

#!/bin/bash

curdir=`pwd`

for dir in `ls`
do
    if [ -d $dir ]; then
        echo "-----$dir----"
        cd $dir
        if [ -d .git ]; then
            repair_url=`git pull 2>&1 | grep 'git remote set-url'`
            if [ ! "$repair_url" == "" ]; then
                echo "---repair:$repair_url--"
                $repair_url
                echo "git pull"
                git pull
            fi
        fi
    fi  
    cd $curdir
done

Author: Too handsome to go out

Guess you like

Origin blog.csdn.net/zmlovelx/article/details/128591134