Git is a distributed source control system.
You could use it to just manage local projects,
but its real power is in how it allows you to work with other
developers by connecting to remote repositories.
You can connect to remotes and push and pull code changes,
all from inside Visual Studio Code.
In the previous movie, I initialized a new local Git
repository for my website project.
I now want to connect it to a new empty remote repository I've
already created on my GitHub account.
On the source control panel, I'll click the three dots to
open the More Actions menu.
From there, I'll come down to the remote submenu and
click "Add Remote."
That opens a pop-up at the top, where I can specify a repository
URL or choose a repository source.
I'll choose to add a remote from GitHub.
If you haven't authenticated VS Code to GitHub,
you'll be prompted to log in.
I've already done that, so after a couple of seconds, I'm
shown a list of repositories in my account.
The empty repository I created as the remote for this project is the
first one here in the list.
I'll select it,
and I'm prompted to give it a name.
Even though my local repository was created first,
I'm going to follow convention and name it
origin.
I can now push my local main branch to the new remote.
From the additional actions menu, I'll select "Push."
Because the remote repository is new and doesn't yet
have any branches,
I get a warning letting me know that and asking if I want to
publish the main branch.
I'll go ahead and do that.
After a couple of seconds,
the publish is successful, and I now have a remote branch I can
interact with and use to share changes with other developers.
So far, I've shown you how to initialize a new local repository
and push it to GitHub from inside VS code.
However, another common workflow is to clone a remote repository
that you don't already have locally.
Let me quickly show you how to do that.
I'm first going to close the folder I already have open.
That reopens the VS Code welcome page.
You can see that there's an option right here to clone
a Git repository.
In case you don't have the welcome screen configured to appear,
I'll also show you another way to clone a repository.
I'll first close the welcome page.
I'll then open the source control panel.
Because I don't currently have a project open,
I have buttons here to either open an existing folder or
clone a repository.
I'll select clone repository.
At the top,
I'll choose that
I want to clone a GitHub repository.
That shows me a list of my own repositories.
I'll search for async-csharp.
That searches my own repositories as well as public GitHub
repositories.
The first result here is the repo for an earlier LinkedIn earning
course of mine.
If I selected it, I would then be prompted to select
a location to store the local repository.
I could then work on the code locally and interact
with the remote,
just as I would with any other Git repository.
In addition to providing a helpful interface for the basic Git
functionality I've already shown you,
VS Code also lets you perform more advanced tasks
such as resolving merge conflicts.
I'll show you how to do that next.