Pulling a Branch from GitHub
Let's keep our local repository up to date by pulling the latest changes from GitHub.
Example:
git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 851 bytes | 9.00 KiB/s, done.
From https://github.com/w3schools-test/hello-world
* [new branch] html-skeleton -> origin/html-skeleton
Already up to date.
Now our master branch is up to date, and we can see that there’s a new branch called html-skeleton available on GitHub.
Check the Current Status
Let’s check the status of our local repository:
Example:
git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
View Available Branches
To see which branches we have locally:
Example:
git branch
* master
Currently, we only have the master branch locally. But since we know the new branch exists on GitHub, we can use the -a option to list all local and remote branches:
Example:
git branch -a
* master
remotes/origin/html-skeleton
remotes/origin/master
Now we can see both our local branch (master) and the remote branches (origin/master and origin/html-skeleton).
Checking Out the Remote Branch
We can see that the html-skeleton branch exists on the remote, but not locally.
Let’s check it out so we can start working on it:
Example:
git checkout html-skeleton
Switched to a new branch 'html-skeleton'
Branch 'html-skeleton' set up to track remote branch 'html-skeleton' from 'origin'.
Make Sure It’s Up to Date
Pull the latest changes from GitHub to ensure our branch is fully up to date:
Example:
git pull
Already up to date.
View All Local Branches
Check which branches we now have locally, and see which one we’re currently on:
Example:
git branch
* html-skeleton
master
Now you can open your favorite code editor and confirm that the files from the html-skeleton branch on GitHub have been pulled into your local repository.