Can I upload folders along with the code on Github?

Asked

Viewed 3,678 times

14

I already put code in my Github repositories once, but now I’m dealing with Netbeans site using HTML5, and I have other folders like CSS, Javascript, and the like. You have the possibility, when you move up the code, to move up these folders as well?

3 answers

16


Git does not allow empty directories. But when I need to upload a folder I create a hidden file inside the directory to upload that directory. For example:

touch pasta/.teste

Apply the git add pasta/ to add a specific folder or git add . to move all folders and changes up.

  • 4

    Well remembered, Jow +1

  • 2

    I never thought of that, +1.

  • 4

    Cakephp uses a file .empty

  • 2

    And a large portion of the community uses the archive .gitkeep.

12

You can, as long as these folders are not listed in the . gitignore file and they are not empty they will be sent to the repository.

Don’t forget to add the folders before commit

$ git add pasta/

If you want to send a folder that does not have files in commit, will be necessary to use some alternative method for this. An approach that I use a lot is to create an empty file with the name .getkeep. That way, I can know the usefulness of the file just by looking at its name.

You can create this file using the command touch

touch pasta/.gitkeep
  • 7

    And if they are not empty. Empty directories are disregarded by git (by default, I believe).

  • For empty folders is just add an index.html with nothing inside, so I do at least

2

I like to do it the way I learned to do it in the projects at Laravel. When I need to have the folder in production, but I don’t need the files inside these folders to be monitored, I create a .gitignore within the folder in question and I place the following:

And put PastaQueEuQuero/.gitignore:

*
!.gitignore

In this case only the file .gitgnore together with the folder is sent to the repository when doing git add PastaQueEuQuero.

Browser other questions tagged

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