Loading
Current section: Commands 17 exercises
lesson

Syncing Local and Remote Git Repositories with GitHub

Git repositories are designed to be distributed, so let's share my-git-notes online.

Sharing a Repository on GitHub

When you create a new repository on GitHub, it will provide instructions on how to start with your remote repository. Because we already have a repository, we're going to use th

Loading lesson

Transcript

00:00 Git repositories are designed to be distributed, so let's share this one online. Now, I'm using GitHub as a Git provider, but you can use any that you're familiar with. I've created a MyGitNotesRepository. I've used the same name here, but it does not have to be the same name as our local repository.

00:19 Now, GitHub does something really nice on new empty repositories, providing instructions on how to start with your remote repository. Because we already have a repository, we're going to use these push an existing repository from the command line instructions. You can just copy and run.

00:39 Let's read through those commands and the output. First, we use git remote to add an origin. Origin is how we refer to our remote repository locally. You could choose a different name, but origin is pretty conventional. The origin repository lives at this address,

00:57 git.github.com colon Chantastic slash MyGitNotes.git. We change the primary branch to main, which is extraneous for us because we were already using main, and then use git push, setting the upstream branch to origin main, so that our local branch,

01:15 main, and origin branch name share the same relative name. All of this output is a result of the push command, just the status of what's being pushed up to the remote repository, and a confirmation that this new remote branch has been added, and our local branch is tracking to that origin branch.

01:33 Let's clear this and run through some of these subcommands. First, we have git remote. Our only remote is origin, which we just added, and we can see details with git remote v for verbose. There are options for removing, editing, or updating these options, which you can find using git help remote. But in most common cases,

01:53 you set it up and you're done. The other subcommand was git branch. Now, locally, we only have our main branch, but if we run git branch, the A or all flag, we'll see that there are technically two. There's main and remotes origin main. Knowing that these are two separate branches represented on your local machine

02:11 will come in really handy in future lessons. For now, let's look at that last command, git push. Git push is how we sync our local repository to our remote repository. We've already done that, so there's nothing left to sync. Let's go back to the web browser and see if all of our changes landed on our remote by hitting refresh. And here they are.

02:31 Everything that we've written so far and committed is represented on this main remote branch.