Current section: Commands 17 exercises

Keeping Branches Updated

When we created our GitHub repo, we ended up with main and remotes/origin/main.

Running the command git branch -a will show us all of our branches, including the remote ones:

$ git branch -a
* main

The * indicates the branch we are currently on.

We used

Loading lesson


00:00 Git pull is actually two commands in one. It's git fetch and git merge. Remember in our previous lesson when I pointed out that git branch all has two branches, main and remote origin main? Let's see what happens when we split git fetch and git merge from git pull. Let's start by making a new remote file.

00:19 We'll make a new note for git pull, txt, give the heading git pull. Commit as add pull note, which gives us commit that only exists on our remote repository. Now let's run both commands of git pull, our fetch and merge. First, let's run git fetch.

00:38 Git fetch pulls down all of the changes into the origin main branch. So when I run git log, we don't see our note on git pull just yet. And we can run git status to see why. Here we see a new message. Our branch is behind origin main by one commit and can be fast forwarded,

00:56 run git pull to update your local branch. Using git branch all again, it's telling us that this branch is up to date, but not our main branch, the one that we're on. So let's run git merge to merge what we've pulled from our origin main branch into our main branch. That succeeded.

01:14 So we can run git log. And once again, main and origin main are both in sync.