0

I've been battling with this for a while.. I need your help.. I'm working on different projects on my hp laptop when I create a new project folder in VScode it uses the same repository as the previous ones. I have 3 projects and when I push all the commits from the 3 projects goes to the same GitHub repository, any idea on what I'm doing wrong please... I've read many things online but I'm just getting more confused

Richard
  • 1
  • 2
  • At a guess, you're creating all your projects as new folders inside an existing repository. – jthill Aug 21 '22 at 16:41
  • Well, maybe but how can I change that? – Richard Aug 21 '22 at 20:12
  • You were correct thanks... My .git folder for was in the same folder I created all my other projects.. That's why but after placing it in the respective folder... I stop having the above issues – Richard Aug 22 '22 at 22:00

1 Answers1

1

Git has never heard of a "solution" and has no idea what a "solution" is. Git stores commits (which in turn store files), and a repository is a collection of commits.

A solution, in Microsoft-speak, is something containing one or more projects. I'm basing this answer on the article here, which you should probably read instead of this answer, especially since I don't use Visual Studio and have zero experience with projects or solutions. Still, I'll put this answer up and see what sort of corrections I get. The best way to find the right answer on the internet is, after all, to proclaim the wrong answer, and then withstand the resulting flames.

Concretely, a project is, apparently, simply a folder containing files. If this is correct——then you can insert any number of projects into a Git repository, since a top-level folder in a Git commit can hold sub-folders, each of which could be a project. The folder seems to become a project if it contains a .csproj file. These files contain XML data, which Git merges very poorly, so do not allow Git to merge .csproj files across branches.

A solution, according to this same web page, is a container for one or more products. Concretely, a solution is stored in a solution file, which is a regular or hidden file whose name ends in .sln or .suo. VS apparently creates and manages this file itself and you are not supposed to edit it yourself.

Putting this together, then, you will want to:

  1. create a new, empty folder and run git init in it;
  2. use VS to create the "solution folder" and the .sln or .suo file;
  3. create one or more projects within this location.

It's not clear to me whether you can just have a single project in a single top level folder without creating a sub-folder first, but it seems that VS manages this stuff for you.

Remember, Git just manages the commits, which then contain files. Git has no idea whether foo.csproj or bar.sln is special in any way. Git is just going to commit the file, or not, based on whether you've told Git to copy the working tree file into Git's index / staging-area and/or whether it was already in Git's index / staging-area from a previous commit. Each commit contains a full snapshot of every file that was in Git's index / staging-area at the time you ran git commit. Extracting a commit—with git checkout or git switch—fills in your working tree from that commit: whatever files are in the commit are now in your working tree.1 If some program or system takes some of those files to be "projects" and/or "solutions", that's the other program's business: Git is indifferent here. Git is merely saving files in commits.


1I'm deliberately glossing over a lot of special cases here. For some of the gory details, see, e.g., Checkout another branch when there are uncommitted changes on the current branch.

torek
  • 448,244
  • 59
  • 642
  • 775