Git: Multiple projects under one directory

432 Views Asked by At

I have a question regarding how to best organize the following using Git. I have multiple java and scala projects that are part of one effort. I would like to have the following structure:

/repos

    /java-project1

    /java-project2

   /scala-project1

  .....

Is it recommended that I do this:

mkdir repos
cd repos

Repos is a simple directory with 3 git repos inside it.

mkdir java-project1
cd java-project1
git --bare init .

on another machine

mkdir repos
cd repos
mkdir java-project1
git init
git add
git commit
git add remote origin [URL]
git push origin master

Do the same for other java and scala project?

or should I do git init in repos once and then just add the projects as three sub directories?

1

There are 1 best solutions below

0
On BEST ANSWER

Your commands seem legit, but for a quite specific conditions, where you have to manually initiate a bare repository on a server. Usually a Git server is used to provide access management and utility features.

This is done on a remote machine. A bare repository has no "usual" files in the directory, just internal Git files. It should also be accessible on the local network or by a URL (this is where a server is useful).

mkdir java-project1
cd java-project1
git --bare init

Note, that if you have some code or resources in repos (not in subfolders), it won't be under any source control. If you need a "nested" structures, look at submodules.

On your local machine.

mkdir repos
cd repos
git clone url1.git
git clone url2.git
git clone url3.git

Now you should have 3 repositories: empty and connected to their remotes (they will go by default name origin in each local repo)

If you're new to Git, I would recommend you to concentrate not on the commands, but on the understanding and workflow. This is like understanding architecture before developing some software. Spend a day getting to know how Git works. It will pay off later.

Git for beginners: The definitive practical guide