Reputation: 7555
I want to create a folder in a GitHub repository and then add files to that folder.
How do I achieve this?
Upvotes: 705
Views: 1586759
Reputation: 123
If you're using Git command line or any command line to update your repo on mac or linux machine, you can run the following commands to create the directory:
Upvotes: 0
Reputation: 5767
To create a folder and upload a file, first create an empty file, then upload the actual file.
To create an empty file that you later upload/update – in a web browser :
<RespositoryName>/
, enter path/to/new-folder/the-file-name
,Now upload the file :
Upvotes: 2
Reputation: 89
Here is my recommended simple solution:
1. Navigate to the repository where you want to create the folder.
2. Click on Add file
in the top-right corner and choose Create new file
.
3. Enter the folder name in the Name field, followed by a /
(slash), and then type "temp.txt" as an example. Next, click on Commit changes
and confirm.
After following these steps, the folder will be created. Once you have uploaded the files into the folder, you can proceed to delete the "temp.txt" file.
Upvotes: 1
Reputation: 91
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
Upvotes: 2
Reputation: 343
Just drag the folder from the Windows Explorer into your Browser where the github Upload Files is shown - now the folder will be add automatically ...
Upvotes: 5
Reputation: 198
Please follow the below steps to create Folders under the repository
1. Login into Github.
2. Select your repository.
3. Tap on "Add file" to the "Create New File" Option.
4. Enter your Folder Name(Ex: RepositoryName/FolderName) and enter "/".
5. Enter file name to commit. I have created README.md for each folder so that it will be easy for me to maintain the details of every folder.
6. Scroll down to the Commit new file section.
7. Choose an option to merge directly to the "master" branch or "Create a new branch".
8. Finally, You need to tap on "Commit new file".
Now, as soon as you tap on Commit new file it will create and take you back to the Repository.
Upvotes: 3
Reputation: 17542
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:
/
. This creates a folder.gitkeep
which is conventionally used to make Git track otherwise empty folders; it is not a Git feature though)Upvotes: 615
Reputation: 2234
Step 1: Click on Create new File
Step 2: Enter the folder name that you want, then press /
Step 3: Enter a sample file name. You must enter some text.
Step 4: Click Commit new file to create the folder
Step 5: Your folder is created!
Upvotes: 51
Reputation: 677
I don't know whenever I use "/" in repository name it is replaced by "-" maybe github changed method of creating folders.
So I'm going to tell you what I did to create a empty folder and to add files.
Upvotes: 2
Reputation: 71
Here is an easy and quick, presently available browser approach to creating folders inside a repository
1)Click the repository / create a new repository.
2)Click create Add file and then create a new file.
3)Give the folder name you want to create with a ' / ' mark and then add a file in it
4)Commit the changes
Click here for the visual representation of the above steps in order.
Upvotes: 2
Reputation: 6519
Click on new file in github repo online.
Then write file name as myfolder/myfilename
then give file contents and commit. Then file will be created within that new folder.
Upvotes: 4
Reputation: 279
To add a new directory all you have to do is create a new folder in your local repository. Create a new folder, and add a file in it.
Now go to your terminal and add it like you add the normal files in Git. Push them into the repository, and check the status to make sure you have created a directory.
Upvotes: 1
Reputation: 448
Actually GitHub does not create an empty folder.
For example, to create a folder in C:\Users\Username\Documents\GitHub\Repository
:
Create a folder named docs
Create a file name index.html
under docs
Open the GitHub for desktop application
It will automatically sync, and it will be there.
Upvotes: 4
Reputation: 1144
For the ones using the web browser, you can do the following:
master
branch.Upvotes: 61
Reputation: 4200
You just create the required folders in your local repository. For example, you created the app
and config
directories.
You may create new files under these folders.
For Git rules:
Git command to do commit:
git add app/ config/
git commit
Then give the commit message and save the commit.
Then push to your remote repository,
git push origin remote
Upvotes: 4
Reputation: 11383
First you have to clone the repository to you local machine
git clone github_url local_directory
Then you can create local folders and files inside your local_directory
, and add them to the repository using:
git add file_path
You can also add everything using:
git add .
Note that Git does not track empty folders. A workaround is to create a file inside the empty folder you want to track. I usually name that file empty
, but it can be whatever name you choose.
Finally, you commit and push back to GitHub:
git commit
git push
For more information on Git, check out the Pro Git book.
Upvotes: 43
Reputation: 6175
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).
Upvotes: 265
Reputation: 131
Create a new file, and then on the filename use slash. For example
Java/Helloworld.txt
Upvotes: 10