How do I create a folder in a GitHub repository?

后端 未结 12 1112
庸人自扰
庸人自扰 2020-12-02 03:40

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

相关标签:
12条回答
  • 2020-12-02 04:10

    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.

    1. Click on New
    2. enter your folder name and nothing else
    3. Click on "Add a README file"
    4. Click "Create Repository"
    5. Now clone the folder you created.
    6. Add files or folders in the local repo
    7. Commit changes.
    8. And there you go.
    0 讨论(0)
  • 2020-12-02 04:12

    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.

    0 讨论(0)
  • 2020-12-02 04:16

    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. 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.
    0 讨论(0)
  • 2020-12-02 04:16

    For the ones using the web browser, you can do the following:

    • Once in the master repository, click on Create new file.
    • In the name of file box at the top, enter the name of your folder
    • Use the / key after the name of the folder. Using this forward slash creates the folder
    • You can see a new box appear next to the folder name wherein you can type the name of your file.
    • In the Commit new file box at the bottom of the page, you can type the description for your file.
    • Select the radio button Commit directly to the master branch.
    • Click on the Commit new file button
    • You will see the new directory will be created.
    0 讨论(0)
  • 2020-12-02 04:16

    Simple Steps:

    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!

    0 讨论(0)
  • 2020-12-02 04:16

    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.

    0 讨论(0)
提交回复
热议问题