From the course: Visual Studio: Source Control with Git and GitHub

Initialize a new repository: PowerShell - Visual Studio Tutorial

From the course: Visual Studio: Source Control with Git and GitHub

Start my 1-month free trial

Initialize a new repository: PowerShell

- [Instructor] The first step for utilizing git is to initialize a git repository. This action is performed once at the beginning of a project. I'll be working with the git commands, in a console window or a shell window and I'm using PowerShell for that. My favorite way of opening PowerShell, is to hold down the Windows key and tap X and then choose from this list. You'll note that I have navigated to this folder, vsGIT\Command. And I'm also in the same folder, I have it open here over in File Explorer. First step is to test whether git is installed, so I'll type in the word git, press Enter. This proves that it's available and it also shows some of the git commands that I can run from PowerShell. We'll look at three of them in this video. We'll look at init, which creates an empty git repository, or reinitializes an existing one, also called git status to look at the working tree status and git log to show the commit logs. Around the git init command and I can see a message in PowerShell that says, initialized empty git repository in this .git folder. And I can also see it over here in File Explorer. Now this is a hidden folder, so if I turn off hidden items, they'll disappear. That's because you shouldn't be messing around with the files that are in here. If you want to look, go ahead and double click on this and these are essentially the database files that are used by git, you don't want to be messing with these directly. You want to use them and manipulate them with git commands or with the Visual Studio IDE. One basic concept to understand with git, is that it is a directory based system so any files that we add to this folder, this command folder can be placed in the git repository. And the same is true for all sub directories that are added to this root folder. Because it is directory based, we can rename this folder or move it to another location and git continues to work with that, any configuration changes, again I'm talking about this folder, this command folder. Now let's run some of those other commands, so over here, type in git status, and I get back, three information lines. The first line says we're on a branch called master. The second line says we've had an initial commit. And the third line says, there's nothing else to do, there's nothing else to commit or add to this repository and tells us some ways we can mitigate that or add files, will show how to do that later in this course. Now I'll call git log, and I get back this message, fatal, your current branch master doesn't have any commits. So I haven't done any work yet that needs to be committed to the repository. Clear the screen. Go back over here, and let me delete this .git folder. Now I've deleted the files that git needs, so if I come back over here, and run git status, I get this message, not a git repository, so I can't find a .git folder. So that's how easy it is to remove the git repository from any folder on your hard drive. So let's re add it, I'll go back and do git init. And now we're ready for the next phase where we look at how to initialize a git repository from Visual Studio.

Contents