I want to create a folder in a GitHub repository and want to add files in that folder. How do I achieve this?
This question is related to
git
github
github-services
Create a new file, and then on the filename use slash. For example
Java/Helloworld.txt
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).
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
For the ones using the web browser, you can do the following:
master
branch.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.
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.
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.
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.
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.
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.
Source: Stackoverflow.com