Reputation: 65
I think my question is simple enough, but I can't find an answer in Google.
I have a GIT project with a master branch and two subbranches. Let's call them 'a' and 'b'.
When I create a file (using GitLab) into master it gets pushed to 'a' and 'b' subbranches. This is the expected behavior.
However, when I create a directory into master I don't see it in 'a' and 'b'.
Is this an expected behaviour? How would you make the directory to propagate into subbranches (using GitLab or the command line)?
Upvotes: 0
Views: 189
Reputation: 89
You can't add empty directories using Git. This is just something you have to deal with. If the directory needs to stay empty you could add a gitignore file that ignores everything.
# Ignore everything in this directory
*
# Except this file
!.gitignore
Upvotes: 0
Reputation: 150605
Directories are not tracked in git
. Files are. Directories are picked up as part of the tree (i.e. where the file is stored) but if you have an empty directory it isn't tracked unless the directory has contents.
The way to have a directory that is tracked is to add an empty file to the root of the directory called .gitignore
. This is a file, which means that if you add it to the repository the directory will be tracked. Also. It is a file that is used by git to know what to ignore. If you leave this empty it will not make any changes to the current list of ignored files. Some people may recommend adding an empty file called .gitkeep
, which seems to be an informal convention. Again. It does not harm, but I prefer to use a file name that has a meaning (.gitignore
) rather that an arbitrarily named one (.gitkeep
).
Upvotes: 1
Reputation: 521178
It isn't possible to git add
an empty directory, which is most likely the reason why GitLab cannot "propagate" it. One workaround would be to add a placeholder file to the directory before you let GitLab commit it.
As others have mentioned, the placeholder file could be a .gitignore
file, but it does not have to be.
Upvotes: 0