Github in VS, where is repository

Bryan Kelly 321 Reputation points
2022-11-23T18:44:30.327+00:00

Windows 11, Visual Studio 2022, C++, Git commands
The goal is to track versions using Git. All the repositories should reside in one umbrella location, on this computer: E:\Z_GIT. A repository was created there for one project. I started a new project and from the tool bar selected: Git -> Commit or Stash.

Evidently, the tool understands there is no repository for this project. The only two options provided an the Git panel are “Create Git Repository” and “Clone Repository. The first is selected.

This is for a local repository, I don’t want to use the on-line one so that option is selected. An image of that screen is provided.

263554-where-is-repository.png

There is one field named Local path. It is the path to the project. Is this the project to be versioned? Is this the path to the new repository? I do not want the repository in the same place as the project.

How does one specify: put this project E:\WX\ripemd_160_expanded_01 into a repository located somewhere within this directory: E:\Z_GIT?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,873 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,630 questions
{count} votes

Accepted answer
  1. Michael Taylor 51,341 Reputation points
    2022-11-23T20:48:25.7+00:00

    Unless I misunderstand your question I think you have a slightly incorrect understanding of how Git, repos and projects work. So let me clarify how it works and then see if your question is answered. Git is just a distributed source control system. Honestly I don't see any benefit in using it without the remote aspect but if that is the way you want to go just be aware that you can royally mess yourself up and potentially lose all your work (and previous versions) so be very, very careful.

    Git has the concept of a repository. A repo is just a collection of files (it doesn't understand folders so you cannot have empty ones). In general everything in a repo should be related in some way. Most companies (and people) use a separate repo for each product but the concept of multiple products in a single repo is supported, just harder to work with. The repo is all Git cares about and everything done within Git is at the repo level. Within a repo you can have any files you want (and logical folders by naming the files using folder-like names). At this point this has nothing to do with projects/Visual Studio/code. In order to have a repo you need to either clone an existing repo or create a new one. When you create a new repo a new folder is created with the repo name (by default) and generally a couple of starter files are created. However the most critical content in there is the hidden .git folder. This is where Git stores all its information. If that folder is ever removed you lose all the repo information. Without a server-backed repo, if you lose this folder then all your history is gone. This is what Git looks for when determining whether a folder is a "repo" or not. Within this hidden folder is the information to link it back to the server-side repo and all your local changes. This is where the stash and commit commands put your changes. Git doesn't care about anything higher than the directory containing the repo so the path to it can be whatever you want. There can be only 1 repo per folder and (ignoring submodules) repos cannot be nested in other repos. A repo is basically the root of the Git world.

    Within a repo, if you want to store code then you'll likely create your solution in the folder. Within that solution is one or more projects where your actual code resides. Again, Git doesn't care about any of this, they are just files to it. You can have any # of solutions and projects in a repo.

    Getting back to your scenario, as I understand it. The root of your repos is E:\Z_GIT. That's fine because Git doesn't care. Each person working on that same repo can use a different path because it has no impact on anything. Within this folder is where you would create your first repo. You can do this in VS or via the command line. Let's assume you wanted to create a repo called MyRepo. Then when you created the repo you would specify the path to be E:\Z_Git\MyRepo. Within this folder is your repo that Git sees and it would auto-create a .git hidden folder. Git is file based so any file changes you make in here would be seen by Git when it looks for changes. At this point you could run git status to see what, if anything, is different.

    Within the repo is where you'll create your VS solution and projects. Out of the box VS creates a folder for each solution so let's suppose you created a new C++ project called MyProject. When you created the project then part of the creation would have been the setting of the solution name. It defaults to the project name but let's suppose you changed it to MySolution. You would also have to specify a local path. Since you want the project in Git you would specify the base path to be E:\Z_Git\MyRepo. After the project is created you'd see the solution and project folders as E:\Z_Git\MyRepo\Mysolution\MyProject. If you use the Git Changes window in VS then it would show that you have added the folders and files to your repo but haven't committed them yet. When you tell Git to commit the changes then your changes would be saved to the .git folder and Git Changes would show nothing has changed. However it will tell you that you have local changes (in .git) that have not been pushed to the remote repo (because you don't have one).

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bryan Kelly 321 Reputation points
    2022-11-24T02:04:43.797+00:00

    You mentioned multiple concepts of which I was unaware. I have been a user of other version managers, but never an admin for any of them. I will have to think about this for a while.
    Your post is very helpful. Thank you for your time and patience.

    0 comments No comments