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– jonrsharpe2021-07-18 07:43:18 +00:00Commented Jul 18, 2021 at 7:43
-
How are you "pushing files"? Git can only push commits.Jörg W Mittag– Jörg W Mittag2021-07-18 07:44:02 +00:00Commented Jul 18, 2021 at 7:44
-
A github folder would be a folder that is created inside the repository, is it not? :Dceaiius– ceaiius2021-07-18 07:45:19 +00:00Commented Jul 18, 2021 at 7:45
-
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– jonrsharpe2021-07-18 07:53:40 +00:00Commented Jul 18, 2021 at 7:53
-
1Does this answer your question? Creating folders inside a GitHub repository without using GitSwissCodeMen– SwissCodeMen2021-07-18 08:02:58 +00:00Commented Jul 18, 2021 at 8: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…
Comments
follow this steps:
- Create folder
- Create files inside folder
- git add .
- git commit -m "add your message"
- git push