0

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!

3
  • the /file-c you are seeing only on remote is a different file, that was created after you cloned, maybe. Commented Mar 11, 2024 at 14:56
  • When you say "subfolder", do you mean a regular directory, or a submodule? It's probably the former unless your clone was explicitly --recursive Commented Mar 11, 2024 at 15:24
  • Thanks for the replies! I didn't use --recursive, so maybe you're right. Is this the reason why? Commented Mar 11, 2024 at 15:31

1 Answer 1

-1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.