1

How to upload folders on GitHub after I have created a repository, I need to upload a folder inside my repository? How will I be able to do that using git-bash or from terminal?

I have added the folder to git by giving command like

$ git add <folder name>
Manthan
  • 63
  • 1
  • 2
  • 10
  • how did you create repository ? If you directly created it in github (using github webstie) then first you need to clone repository and then add, commit and push folder. – user Jul 14 '19 at 09:41
  • I have created my repository in GitHub webpage and created a folder in my local storage from git-bash and linked that repository with that directory using my repository ssh authentication. – Manthan Jul 14 '19 at 10:23
  • I saw the link you shared for your work. you are doing " git init" which means you are initiating a new repository. You don't need new repository. you have already created repository using github webpage. you should only clone that one and for that you should do git clone instead of git init and then create a new folder and do git add . then git commit and then git push. I hope it helps. – user Jul 14 '19 at 12:18
  • It didn't worked in my case, if you could please show me your working screen video or make a short tutorial for it, it will surely help. Thank you! – Manthan Jul 15 '19 at 07:25
  • I think you are trying to add empty folder. If this is the case, it wont work. As per Git documentation, Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. Please see this for more info : https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F . – user Jul 15 '19 at 08:13
  • 1
    You can also opt to create a .gitignore or a .gitkeep file inside the directory. See this :https://stackoverflow.com/questions/115983/how-can-i-add-an-empty-directory-to-a-git-repository – user Jul 15 '19 at 08:24
  • Thanks a lot, I wasn't aware about there terms. @RajniKewlani – Manthan Jul 16 '19 at 06:17
  • Great! consolidating all above conversation in my answer. – user Jul 16 '19 at 08:04

3 Answers3

4

Git does not support addition of empty folder. However you can create .gitignore or .gitkeep or any other hidden file in folder and add it.

As per Git documentation, Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own.

Please see this for more info : https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F

You can opt to create a .gitignore or a .gitkeep file inside the directory.

See this for more information :How do I add an empty directory to a Git repository?

user
  • 867
  • 9
  • 21
2

In this case you want to push an empty folder. You need to add something to the folder like .gitignore before you push to your remote repository.

If you add a remote repository just do the following steps

  1. git add <folder name>
  2. git commit -m "a commit message"
  3. git push -u origin master

and if not first add remote repository then do the steps 1 to 3:

git remote add origin <repository url with a .git at the end>

El.
  • 1,217
  • 1
  • 13
  • 23
  • 1
    I don't think what you actually said works! Here's a link of your code workings [https://drive.google.com/file/d/1pj1GpBAfuhKj6blw6NsPInSlecWxL7Cq/view?usp=sharing] – Manthan Jul 14 '19 at 10:35
  • https://stackoverflow.com/questions/115983/how-can-i-add-an-empty-directory-to-a-git-repository – El. Jul 14 '19 at 10:52
-2

Git does not support creating empty sub-folders.