Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot add directory to git repo

I have a git repository at repo on my local computer, and on GitHub I have a repo online with main branches main and b2. On my local computer I have branches master and b2. The local repo directory has subdirectory repo\subdir. On GitHub this subdirectory is not showing up in online branch b2 (or any other branch, but it will be victory if I can get it on b2).

Now when I pull up a Powershell pointed to repo and enter git checkout b2 it says that I’m on branch b2. I run git add . and it gives no error messages. If I enter git status it says that nothing is untracked. I commit and it says the branch is clean, nothing to commit. I push with git push -u origin b2 it says

Everything up-to-date
branch 'b2' set up to track 'origin/b2'.

Everything looks as good as I can imagine!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I go to the GitHub page, and everything else in the repo is there, except for subdir. No branch, including b2, contains subdir. I go to Pull Requests, set it to main <- b2 and it says there are no differences.


This seems like, whatever this is, I’d expect it to be common. But when I search for other people with the problem, I don’t see anything that looks applicable. These are my nearest search results:

Unable to add a directory to git repo

Add directory to existing git repo without subproject?

And I continually asked ChatGPT what to do and I seem to have exhausted all of its ideas.

>Solution :

Git does not track folders, it tracks files.

Your folders probably contain no files, therefore git has nothing to track.

Some people work around this issue by adding a 0-byte file called .gitkeep to each folder that they want to keep in the repository, even if empty.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading