Py文件夹下多Git仓库URL被批量修改的异常问题求助
It sounds like you’re spot-on with your suspicion—your entire 'Py' folder has been turned into a single Git repository, which is why changing the remote URL in one subfolder affects all others. Here’s a step-by-step fix to get your independent project repos back:
Step 1: Confirm the Root Cause
First, let’s verify the current state of your folders:
- Open your terminal and navigate to the 'Py' folder:
cd Py - Run
ls -la—if you see a.gitdirectory listed here, that’s the parent repo causing the issue. - Check one of your subfolders (e.g., folder1):
cd folder1 && ls -la—if there’s no.gitdirectory here, this folder is just a subdirectory of the parent 'Py' repo, not an independent repo.
Step 2: Back Up the Parent Repo (Just to Be Safe)
Before making changes, let’s back up the parent’s .git folder so you can restore it if anything goes wrong:
- Navigate back to the 'Py' folder:
cd .. - Rename the parent
.gitfolder:mv .git .git_parent_backup
Step 3: Restore Independent Repos for Each Subfolder
Now we’ll get each project folder back to being its own separate repo. There are two common scenarios:
Scenario A: You Previously Had Independent Repos
If you originally set up each subfolder as its own repo, their .git directories might have been accidentally deleted or moved. If you have backups of those .git folders, simply move them back into their respective subfolders.
Scenario B: You Need to Reinitialize Independent Repos
If you don’t have backups, reinitialize each subfolder as a Git repo and reconfigure its remote URL:
- For each project subfolder (repeat these steps for folder1, folder2, etc.):
- Navigate to the subfolder:
cd folder1 - Initialize a new Git repo:
git init - Add all existing project files to the repo:
git add . - Create an initial commit:
git commit -m "Restore independent project repo" - Set the correct remote URL (replace
your-project-urlwith the actual repo URL):git remote add origin your-project-url - Verify the remote is set correctly:
git remote -v
- Navigate to the subfolder:
Step 4: Verify the Fix
Once you’ve set up all subfolders as independent repos:
- Go into each subfolder and run
git remote -v—each should show its unique remote URL. - Test changing the URL in one subfolder with
git remote set-url origin new-test-url, then check another subfolder’s remote—this time it won’t change.
From now on, avoid initializing a Git repo in the parent 'Py' folder itself—keep each project’s repo isolated to its own subfolder.
内容的提问来源于stack exchange,提问作者Valeria S.

