简体   繁体   English

如何根据目录结构正确设置Git和GitHub存储库

[英]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. 场景-这是我的目录,并且我试图在GitHub中分离目录和两个不同的存储库,我不确定自己做错了什么,并希望stackoverflow社区可以为我提供帮助。

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

So I navigated to in Bash to 所以我在Bash中导航到

+- 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? 1)我该如何解决?

2) What did I do wrong? 2)我做错了什么?

The signature of the git init command, ignoring extraneous arguments, is: git init命令的签名(忽略无关的参数)为:

git init [directory]

Running this command initializes a git repository in the directory specified. 运行此命令将在指定目录中初始化git存储库。 If you omit the directory parameter (it is optional), the current directory (ie that printed on a Unix box by the pwd command) will be initialized with a git repository. 如果省略directory参数(它是可选的),则当前目录 (即通过pwd命令在Unix框上打印的目录 )将使用git存储库进行初始化。

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 . 然后将目录(使用cd命令)更改为该目录,并调用git init A .git directory will be created inside the current directory, and the directory will contain your working tree. 将在当前目录创建一个.git目录,该目录将包含您的工作树。


If your repositories are already present at GitHub, use the git clone command to clone them to your machine. 如果您的存储库已经存在于GitHub上,请使用git clone命令将它们克隆到您的计算机上。 The git clone command has the following signature (again, dropping extraneous parameters): git clone命令具有以下签名(同样,删除无关的参数):

git clone REPO [directory]

where REPO denotes the path at which the remote repository can be found. 其中REPO表示可以找到远程存储库的路径。 This might be a URL or another directory in your local file system. 这可能是URL或本地文件系统中的另一个目录。

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. 在这种情况下,如果您指定了可选的directory参数,则该存储库将通过该名称在提供的路径下在新目录中检出。 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. 在Unix系统上,我建议使用git手册页来了解有关命令的更多信息。 They are comprehensive. 它们很全面。 For any git command, eg git something , a corresponding man page can be found by replacing spaces with hyphens, ie invoke man git-something . 对于任何git命令,例如git something ,可以通过用连字符替换空格来找到相应的手册页,即调用man git-something man git-init , man git-clone , etc. man git-initman git-clone

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM