Karthick
Karthick

Reputation: 4766

How to include two different folders into the same git project?

Hey, i am working on two programs at the same time. Assume A and B are two different folders in different directories. Is it possible to have them both be a part of the same git project? Because i use data from A as input for B, but since A is a web app, i've put it in public_html while B is in a different folder.

Upvotes: 9

Views: 4038

Answers (3)

Marcin Borkowicz
Marcin Borkowicz

Reputation: 1

On Windows, you can achieve the same result by doing the following:

  1. Supposing you have the Project A in the folder'C:\webstack\Project A' and the Project B in 'C:\server\Project B'. Files of each project are already there respectively. Please note in this point it doesn't really matter what's a path to each folders, unless they are in a normal filesystem on a local, phisical drive(s)

  2. Create a folder for your GIT project; say 'C:\repos\git-project-A-B'

3.In Windows cmd type:

cd 'C:\repos\git-project-A-B\'
  1. Now you are in you destined GIT working directory. Time to create hard-linked directory junctions for Project A folder (directory)

    C:\repos\git-project-A-B> mklink /J /H "C:\webstack\Project A"
    

and the same for Project B:

C:\repos\git-project-A-B> mklink /J /H "C:\server\Project B"
  1. If the operations in the point 4 have been done correctly, by typing the command dir /all in the working directory you should see at least two hardlinks (junctions):

    (date) (time) Project A [c:\webstack\Project A]

    (date) (time) Project B [c:\server\Project B]

  2. Now, the fun part! You can work normally in each projects folders, but you initialize you GIT repo only in C:\repos\git-project-A-B. From now on, you can do as follows

    C:\repos\git-project-A-B> git add "Project A"

and

C:\repos\git-project-A-B> git add "Project B"

and then commit changes, invoke status reports, repo logs etc.

It works like a charm!

Upvotes: 0

Brian Campbell
Brian Campbell

Reputation: 332776

Create a git project with the two directories, put it somewhere else, and then just create symlinks in the two locations that you need the two folders.

$ ls -a myproject
. .. .git A B
$ ln -s myproject/A A
$ cd public_html
$ ln -s ../myproject/B B
$ cd ..
$ ls 
myproject A public_html
$ ls public_html
B

Upvotes: 11

user229044
user229044

Reputation: 239240

Short answer, you can't. Make each a separate git repository. Two different programs don't belong in the same repository anyways.

Long answer: The only way would be to create a git repo higher up in the file system at the point where the two directories share a common ancestor. This might even be the root of your file system. You could add each of the two project directories to the repo and specify everything else in .gitignore. This is obviously less than ideal.

Upvotes: 4

Related Questions