'Git manage a portion of code to another repo

I have the following situation: My code base folder has two subfolders:

  • main_code
  • experiments

Right now, only the code inside main_code is tracked added and committed. There is also a remote ("origin") to a external repository.

What I want to do is to put all the code in experiments (that is not tracked now) in another external repository. How can I do that?

I was thinking of adding another remote (other than "origin"), say experiment_repo, but if I do that, how can I put only the code in experiments in said repo?

EDIT: Just to clarify:

main_code annd experiments are subfolders of base_folder and .git is in the base_folder .



Solution 1:[1]

If your repository is in main_code (meaning there is a main_code/.git subfolder), and experiments is not yet in a repository, all you need to do is (since no part of experiments have been staged, tracked or committed):

cd base_folder
mv experiments ..
cd ../experiments
git init .
git add .
git commit -m "Import experiments code"
git remote add origin https://github.com/new/empty/repository
git push -u origin main

You could install and then use the gh CLI tool, and create your remote repository with gh repo create (after a gh auth login first).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1