337

I want to add a new folder to my newly created GitHub repository without installing the Git setup for (Mac, Linux, and Windows). Is it possible to do so?

I can't have Git all the time with me when I work on different systems/machines. I know how to add files directly in a repository on github.com/[USER]/[REPO]. Can we create a folder as well?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
softvar
  • 17,917
  • 12
  • 55
  • 76
  • 1
    You would probably find [codenvy](http://codenvy.com) or [Cloud 9](http://c9.io) compelling. – Derek Adair Feb 18 '15 at 00:16
  • 5
    Possible duplicate of [How to create folder in github repository?](https://stackoverflow.com/questions/12258399/how-to-create-folder-in-github-repository) – Innat Jun 16 '18 at 15:04

4 Answers4

742

After searching a lot I find out that it is possible to create a new folder from the web interface, but it would require you to have at least one file within the folder when creating it.

When using the normal way of creating new files through the web interface, you can type in the folder into the file name to create the file within that new directory.

For example, if I would like to create the file filename.md in a series of sub-folders, I can do this (taken from the GitHub blog):

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
softvar
  • 17,917
  • 12
  • 55
  • 76
  • 25
    The requirement of having at least one file in the folder is actually [a shortcoming of Git itself](http://stackoverflow.com/a/115992/1523776) – Benjamin Hodgson Sep 01 '14 at 12:10
  • 51
    It would be great if they made this more intuitive, like adding a "create folder" button to the web interface, while editing a file if not at the root. What they did is cool, but probably confusing to new/nontechnical users. – trysis Nov 14 '14 at 17:23
  • 2
    Rawr, yes, this is very not intuitive for first-timers. I like how they do it, but seriously, why could I not find it in their docs? – Phil Tune Jun 17 '15 at 15:55
  • 2
    It probably has something to do with the fact that in under Linux/UNIX, there is no difference between folders and files. A folder, or directory, is just a file with the names of other files in it. http://tldp.org/LDP/intro-linux/html/sect_03_01.html I know it doesn't make sense to Windows folk, but it's true. – Rick Henderson Apr 06 '16 at 01:57
  • 1
    This is nice, but it only works for text: for, say, a PDF, the equivalent "Upload file" button does not allow the path to be changed. – Eric O. Lebigot Sep 28 '16 at 10:27
  • 4
    @EOL True, but you could use this technique to create a random text file, then browse to the new folder, upload a file, then remove the text file. It's messy, but it does work if you need it. – Amy Barrett Mar 18 '17 at 12:29
  • @trysis GitLab did it – Andrea Ligios Jun 07 '18 at 22:37
  • I'd say using a `.gitkeep` file here would be appropriate if you don't want to make a file with any contents. – mickmister Nov 14 '18 at 02:05
  • This doesn't seem to work any more. The UI is different, and slashes get translated into dashes when you save. – wu-lee Nov 23 '19 at 12:52
114

When creating a file, use slashes to specify the directory. For example:

Name the file:

repositoryname/newfoldername/filename

GitHub will automatically create a folder with the name newfoldername.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Malcolm McSwain
  • 1,888
  • 2
  • 15
  • 17
  • 3
    Hmm. I dont tend to create files using the github web app. Rather, I tend to use git add running in my local shell. How would I work your advice into my git command sequence running on my localhost? Typically I run this sequence in a bash shell on my localhost: git init, git add file1.abc, git add file2.abc, git commit, git remote add origin somegithuburl, git push -u origin master THank you – Geoffrey Anderson Jan 20 '15 at 15:25
22

You can also just enter the website and:

  1. Choose a repository you have write access to (example URL)
  2. Click "Upload files"
  3. Drag and drop a folder with files into the "Drag files here to add them to your repository" area.

The same limitation applies here: the folder must contain at least one file inside it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
3

Another thing you can do is just drag a folder from your computer into the GitHub repository page. This folder does have to have at least 1 item in it, though.

Elijah Mock
  • 587
  • 8
  • 21