I started working on git and github recently and whenever I push files from git to github, it just pushes them into the repository right away, but I want to first of all, create a folder in my repository from git if it's possible and then push those files into that folder. Is it possible?
-
1What's a "GitHub folder"? – jonrsharpe Jul 18 '21 at 07:43
-
How are you "pushing files"? Git can only push commits. – Jörg W Mittag Jul 18 '21 at 07:44
-
A github folder would be a folder that is created inside the repository, is it not? :D – ceaiius Jul 18 '21 at 07:45
-
I don't know, when using git push, doesn't git upload files on github repository? – ceaiius Jul 18 '21 at 07:46
-
2Maybe you're thinking of _branches_? You can have directories _within_ your repo just fine, but that's up to you not git/GitHub. – jonrsharpe Jul 18 '21 at 07:53
-
Gosh It's hard to explain when I know so little. Say, If I have a folder in my branch repository, called "TEST", how do I upload files in it using git? – ceaiius Jul 18 '21 at 07:56
-
What do you mean "branch repository"? A branch _in_ your repository? Does it _contain_ a directory named TEST, or is it a branch _named_ TEST? You should probably run through some introductory git tutorials to get to grips with the model and nomenclature, that would make it much easier to communicate what you actually want. – jonrsharpe Jul 18 '21 at 07:58
-
1Does this answer your question? [Creating folders inside a GitHub repository without using Git](https://stackoverflow.com/questions/18773598/creating-folders-inside-a-github-repository-without-using-git) – SwissCodeMen Jul 18 '21 at 08:02
3 Answers
You can only push commits, where files contain. And this files can be everywhere, also in a folder. So it is possible.
To have a folder in your remote repository, you must create a folder on your local repository (on your computer). As example you can create a folder as follow:
mkdir myFolder
Then navigate to this folder and create a file
cd myFolder
touch myFile.txt
(You can create this also on the Desktop of your computer instead of terminal/console). Now you are able, to push your folder with the file to your remote GitHub repository with committing and pushing
git add .
git commit - m "add new folder with file"
gut push
Now you have your desired folder in the remote repository.
Little note: You don‘t push files from Git to GitHub, you push commits, where files contain, from your local repository to the remote repository, where in your case is GitHub. I think you are still missing some basic git knowledge. Here a link as reference to read and learn more of Git and its rules: https://git-scm.com/book/en/v2
EDIT:
The question wasn‘t clear for me. After the comments, it is clearer, thst you want to create the folder IN GITHUB in your repository. For this look at this question: Creating folders inside a GitHub Repository without using Git
After creating this folder, you must git pull
that you become this folder also on your local repository!
But I see no reason to create a folder in GitHub repository. That‘s actually not in the sense of git…

- 4,222
- 8
- 24
- 34
you can use the branches if you need to do something like archiving .| Also after that you can merge them into the master branch

- 39
- 11
follow this steps:
- Create folder
- Create files inside folder
- git add .
- git commit -m "add your message"
- git push

- 1,062
- 5
- 9
-
I know about that, I'm asking if I could create the folder directly from git and not github and then push files in the folder from git – ceaiius Jul 18 '21 at 07:54
-
The folder is not created from GitHub in this response. I don't understand your question/comment. A folder you see on GitHub is necessarily a folder you'll see on your local repository as well. – Gaël J Jul 18 '21 at 08:03