How do I create a folder inside my Github repository?

Asked

Viewed 14,398 times

1

How I create a folder in my repository so I can organize my files and not leave everything in the same repository folder on Github? this can be done by creating the folder using the command line or on itself Github?

  • Hello! Just create the directory, put some file in (Git does not versioning empty directories), do the commit and then the push. What have you ever tried to do?

  • Hi! in the question I don’t talk about this problem in detail, but in context it’s the same question steps, so to be precise, I’m new to Github and I don’t know much, but I’ve created a repository pagina and uploaded a file from my PC which is index.html, but now I need to create a CSS folder to put my file style.css within it.

  • Right. You tried to do what I said in my previous comment?

  • No! I’ll try to find out what a commit or push to try to do, because I don’t know.

3 answers

3

A Github repository is a Git repository, and it works exactly like one, either by command line, but also the site provides tools for some of the main commands, which includes creating files, see:

Remember: Git will not add content-free folders to the repository!

  1. Creating a file in a new folder by terminal

In a new repository, create a folder, navigate to it:

git init
mkdir folder
cd folder

A imagem mostra a execução dos comandos acima

Then create a new file, opening the new file in Notepad you can add content, then add the file to Git staging and commit:

New-Item file.txt
Notepad .\file.txt
git add *
git commit -m "New file"

A imagem mostra a execução dos comandos acima

The file was added to the repository, see the log:

git log

A imagem mostra a execução do comando acima

  1. Creating a file in a new folder through the Github web interface

Click on the "Create new file" button (1)

A imagem mostra o botão a ser clicado: "Create new file"

In the text box that will open, type the name of the folder, ie "Folder" (1):

inserir a descrição da imagem aqui

To indicate that a new folder is being created, type "/" (character: bar), at this time the text previously typed will be moved to the left becoming a folder:

inserir a descrição da imagem aqui

Then type the name of the file you want to create, make the comment to the commit in the field below the screen, when you finish typing the file contents and make the commit by clicking the button.

1


Just create the folder inside the local repository and put some file in it. Git will automatically recognize it and when you run PUSH that folder as well as the files and subfolders will be synchronized with your remote repository.

Note that Git does not monitor folders but files, so only folders containing some file will be created/synchronized.

  • Thanks! but in relation to Github there is no way to do there?

  • On the site t know any options. Maybe it is due to the premise of Github not controlling folders but files and that theoretically the bases of your projects should be defined locally and only then synchronized.

-2

That’s exactly how colleagues explained it, git doesn’t add folders without any content, but I went through the same situation and what I did was create a folder and within that folder create a file and then and then all the basic stages. git add . or the specific file, git status, git commit -m "text".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.