How do I push a file into its subfolder in git repository?

64 views Asked by At

I'm quite new to git and I'm facing a (surely) trivial problem.

I have cloned a repository and currently working in one of the subfolders (subdirectories).

The structure is something similar to

Main repository
|-subfolder_1
  |--file_a
  |--file_b
|-subfolder_2
|-subfolder_3

In the cloned copy, I have created in subfolder_1 a new file file_c. I can correctly add the file, but the problem I have is that when I push the file file_c, it gets updated/committed into the main repository and not in the subfolder subfolder_1, i.e.

Main repository

|-subfolder_1
  |--file_a
  |--file_b
|-subfolder_2
|-subfolder_3
|-file_c

With the command git remote -v I get the https of the Main repository for push and fetch.

What am I getting wrong? Thanks a lot!

1

There are 1 answers

1
CodeWizard On

Whenever you clone a git repository, the "root" folder is the most top folder of all your files.

If you wish to add "New git repository" under the root folder you should add submodule.

In your case you clones a repository, all your files will be added under the root (with respect to their relative path).

Example:


git clone ....

# This file will be added under the main folder
touch a.txt
  • Sound like you did not create the file under the folder.
  • Check your structure with ls or with `tree' command

enter image description here

Start reading from bottom up enter image description here