如何将现有GitHub仓库移入指定主文件夹?操作疑问求助
Hey there! Let me break this down for you clearly—your approach actually does work for creating a visual "folder" grouping on GitHub, but there are some key details and caveats to keep in mind.
1. 你的操作为什么有效(以及它的本质)
GitHub treats repository names with slashes as visual folder groups, not actual file system folders. So when you rename a repo to web_fundamentals/your-repo-name, it will show up under a collapsible web_fundamentals "folder" in your GitHub profile's repository list. You can even add a second level, like web_fundamentals/intro_oop_python/your-repo-name, to create nested subfolders exactly as you mentioned.
Important note: These are still completely independent Git repositories—they don't share storage, permissions, or Git history. The folder structure is just a UI trick to organize your repos visually.
2. 完整的操作步骤(优化你的方法)
If you want to proceed with this grouping, here's how to do it smoothly:
- Go to the Settings page of each repository you want to move
- In the "Repository name" field, update the name to include your desired path (e.g., change
old-repo-nametoweb_fundamentals/old-repo-nameorweb_fundamentals/intro_oop_python/old-repo-name) - Click "Rename" to confirm. GitHub will automatically set up a temporary redirect from the old repo URL to the new one, so links won't break immediately.
3. Critical things to fix after renaming
- Update local clones: For every repo you renamed, run this command in your local project folder to point to the new remote URL:
git remote set-url origin https://github.com/your-username/web_fundamentals/your-repo-name.git - Update external references: Any links in documentation, CI/CD pipelines, scripts, or third-party tools that point to the old repo URLs need to be updated. The GitHub redirect works for a while, but it's not permanent.
- Check permissions: If you had collaborators or team permissions set up, they'll carry over to the renamed repo—but double-check to make sure nothing got messed up during the rename.
4. Alternative: If you want actual file system folders
If your goal was to have all code in a single repository with real subfolders (instead of independent repos), you'd need to merge all your 15 repos into one new web_fundamentals repo. Here's a quick overview:
- Create a new empty repo named
web_fundamentals - Clone it locally, then create subfolders like
intro_oop_pythoninside it - For each of your old repos, copy their contents into the appropriate subfolder in
web_fundamentals, commit the changes, and push to GitHub.
This approach is better if all your projects are part of a single codebase, but worse if you need each project to have its own Git history, permissions, or release cycle.
内容的提问来源于stack exchange,提问作者Josiah McPeak

