2

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!

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.

Addem
  • 3,635
  • 3
  • 35
  • 58
  • 3
    Is there anything _in_ that subdirectory? – tkausl Jul 28 '23 at 16:05
  • @tkausl there are further subdirectories which are all empty. However, I'm only just realizing that they're empty -- they were supposed to have many files, all of which are missing now. Luckily I had them backed up elsewhere and I'm adding them back in now. Will report an update soon. – Addem Jul 28 '23 at 16:06
  • 1
    @tkausl Ah well, whatever that was, it was the issue! I don't know how the files went missing, but when I add them back in then everything is fine now! Thanks! – Addem Jul 28 '23 at 16:08

1 Answers1

1

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.

Jay
  • 3,640
  • 12
  • 17