Creating & committing folders in a GH Branch in terminal

I need a little clarification on how this works. I know that, with files, if I'm in a certain branch, say main, and I create a new file there (say, myFile.html). If that file is unique to main (the filename does not exist in any other branches), then if I fail to commit that newly created unique file, and then switch to another branch (say, Branch-1), that Git's 'Uncommitted Changes Carryover' will be triggered, and I'll be allowed to switch to Branch-1 , but in Branch-1, I will see a temporary copy of the uncommitted myFile.html inside the Branch-1 directory. It's only once I finally commit myFile.html to a particular branch, that I will no longer see temporary copies of it ("carried over") into other Branch directories. After committing, it will only be visible in the directory associated with the Branch it was committed to. That's with files. I wanted to test whether this behavior also applied when creating folders in Github Branches. For example, if I'm in main and I do a mkdir components-main and then fail to commit it, and immediately switch to Branch-1, will I also see a "carried over" temporary copy of the components-main folder inside the Branch-1 directory? And then likewise, if I go back and commit components-main to main , and switch to Branch-1 again, will I stop seeing that 'carried over' components-main copy in Branch-1's directory? I started to run this experiment I, and here's what happened: Inside Branch-1, I created a components_Branch1 folder and purposely didn't commit it. I then switched to main and saw that the folder was listed in main's directory. I then switched back to Branch-1 to commit the folder to Branch-1, but when I ran git status, it told me there was nothing to commit. What am I not understanding?
No description
7 Replies
Jochem
Jochem•13mo ago
git ignores empty folders so unless you put files in there, it won't do anything with them
thethingisback
thethingisbackOP•13mo ago
So it doesn't even treat as something needing to be committed, it just act liek it doesn't exist at all once I do move a file into it, I'm assuming that will be recognized as a commit-able action at that point.. And so if I've moved a file into it, failed to commit that move, and switch to another branch, I'll see a 'carried over' copy of the folder + file in the other branch's directory?
Jochem
Jochem•13mo ago
it should yeah generally, it's not something you'd run into too much if you're switching branches, you can either do a quick commit to make sure your changes are safe, or you use git stash if you can't, but you wouldn't just leave files dangling about
thethingisback
thethingisbackOP•13mo ago
okay that makes sense and so creating a folder, say I don't have anything to put inside of it just yet, but I know I'll eventually need that folder.. I'll just have to deal with that folder appearing in every directory up until I can finally commit a file to it? Or as a practice I should just hold off on creating folders in Git branches until I know I have a file to put in it and commit to it.
Jochem
Jochem•13mo ago
you can always put a .gitignore file in the folder, or something the only time I've really had this come up was with a project that used Smarty as a template system, it needed a compiled template cache folder that was part of the repo, but empty. Usually you don't make folders unless you have files in there
Hans
Hans•13mo ago
I have seen people adding an empty .gitkeep file to an empty folder to make sure it commits.
Jochem
Jochem•13mo ago
that works too 😄
Want results from more Discord servers?
Add your server