Moojjoo
Moojjoo

Reputation: 753

How to correctly setup Git and GitHub repositories based on directory structure

Scenario - Here are my directories and I am trying to seperate the directories and two different repositories in GitHub, I am unsure what I am doing wrong and was hoping the stackoverflow community could help me out.

+- Source    
|   
+-- repos   
    |   
    +--LearnGit
    |   
    +--TestGit        

So I navigated to in Bash to

+- Source    
|       
+-- repos    
    |       
    +--LearnGit and ran git init

However, the result was the following

+- Source    
|       
+-- repos    
    |       
    +--LearnGit    
    |       
    +--TestGit    
    +--.gitattributes   
    +--.gitignore

I was hoping each folder would have its own repository

+- Source    
|   
    +-- repos    
    |    
         +--LearnGit    
         +--.gitattributes    
         +--.gitignore    
    |    
         +--TestGit    
         +--.gitattributes    
         +--.gitignore 

1) How do I fix this?

2) What did I do wrong?

Upvotes: 0

Views: 44

Answers (1)

Cosmic Ossifrage
Cosmic Ossifrage

Reputation: 5379

The signature of the git init command, ignoring extraneous arguments, is:

git init [directory]

Running this command initializes a git repository in the directory specified. If you omit the directory parameter (it is optional), the current directory (i.e. that printed on a Unix box by the pwd command) will be initialized with a git repository.

If your repositories are new, you fix your problem by deleting the directory tree structure and starting again. The easiest method has the directory structure created first, including the directory in which the repository is to be. Then change directory (use the cd command) into that directory, and call git init. A .git directory will be created inside the current directory, and the directory will contain your working tree.


If your repositories are already present at GitHub, use the git clone command to clone them to your machine. The git clone command has the following signature (again, dropping extraneous parameters):

git clone REPO [directory]

where REPO denotes the path at which the remote repository can be found. This might be a URL or another directory in your local file system.

In this case, if you specify the optional directory argument, the repository will be checked out in a new directory by that name at the provided path. Otherwise, a new directory matching the last path component of the foreign repository will be created in the current working directory, and the repository checked out there.


On Unix systems, I recommend using the git man pages to understand more about the commands. They are comprehensive. For any git command, e.g. git something, a corresponding man page can be found by replacing spaces with hyphens, i.e. invoke man git-something. man git-init, man git-clone, etc.

Upvotes: 1

Related Questions