Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a folder in a GitHub repository?

I want to create a folder in a GitHub repository and want to add files in that folder. How do I achieve this?

like image 782
Sagar Avatar asked Sep 04 '12 07:09

Sagar


People also ask

How do I create a folder within a repository?

To create a new folder in a repository click “create a new file.” Type your new folder's name in the area where you would write the file name, and at the end of the file name type a “/” to initilize it as a folder. After this you can create a new file in the folder.


2 Answers

TL;DR Use / in the file name field to create folder(s), e.g. typing folder1/file1 in the file name field will create a folder folder1 and a file file1.

Original answer
You cannot create an empty folder and then add files to that folder, but rather creation of a folder must happen together with adding of at least a single file. This is because git doesn't track empty folders.

On GitHub you can do it this way:

  • Go to the folder inside which you want to create another folder
  • Click on New file
  • On the text field for the file name, first write the folder name you want to create
  • Then type /. This creates a folder
  • You can add more folders similarly
  • Finally, give the new file a name (for example, .gitkeep which is conventionally used to make Git track otherwise empty folders; it is not a Git feature though)
  • Finally, click Commit new file.
like image 95
Sнаđошƒаӽ Avatar answered Sep 24 '22 21:09

Sнаđошƒаӽ


Git doesn't store empty folders. Just make sure there's a file in the folder like doc/foo.txt and run git add doc or git add doc/foo.txt, and the folder will be added to your local repository once you've committed (and appear on GitHub once you've pushed it).

like image 43
moopet Avatar answered Sep 21 '22 21:09

moopet