Home > Blockchain >  How to connect two separate folders into the same GitHub repository?
How to connect two separate folders into the same GitHub repository?

Time:03-05

I have already made a GitHub repository with a folder1, but I have a ../etc/etc/folder2 that I would like to add into the same repository because they both are a part of the same project.

As you can see these two folders are not super close to each other, but they are in the same linux file system. How can I add folder2 to my existing GitHub repository that contains folder1?

CodePudding user response:

What I ended up doing was creating the repository in the root directory.

I created a .gitignore file to ignore all files except the two folders that I wanted in the repository.

## Ignore everything...
*

## Except...
folder1
folder1/*
path/to/folder2
path/to/folder2/*

CodePudding user response:

You would need to, locally on your Linux machine, move or copy the folder2 in your local cloned repository, add and commit.

Then you can push, in order to see folder2 in your remote GitHub repository.


The alternative is:

  • make a Git repository in ../etc/etc/folder2, push it to a separate GitHub repo folder2
  • reference the remote GitHub repository folder2 as a submodule in your first local cloned repository

That is:

cd /path/to/folder1
git submodule add -b main -- https://github.com/<me>/folder2

That way, you have the repo folder2 referenced by your main repository.

If you change anything in folder2 (original path), add, commit and push.

Then, from the first local cloned repository, git submodule update --remote is enough to update the folder2 submodule content.

  • Related