Curriculum
Course: Git
Login
Text lesson

Pull Branch from GitHub

Pulling a Branch from GitHub

Now continue working on our new branch in your local Git repository.

First, pull from the GitHub repository again to ensure your code is up-to-date.

[user@localhost] $

git pull
remote: Enumerating objects: 5, done.
emote: 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/code7school-test/hello-world
 * [new branch]      html-skeleton -> origin/html-skeleton
Already up to date.

Our main branch is now up-to-date, and we can see that a new branch is available on GitHub.

Perform a quick status check:

Example

[user@localhost] $

git status
On branch master
Your branch is up to date with ‘origin/master’.

 
nothing to commit, working tree clean

And confirm which branches we have and which one we are currently working on.

Example

[user@localhost] $

git branch
* master

We don’t have the new branch in our local Git yet, but we know it’s available on GitHub. We can use the -a option to view all local and remote branches.

Example

[user@localhost] $

git branch -a
* master
  remotes/origin/html-skeleton
    remotes/origin/master

Note: branch -r shows only remote branches.

We see that the html-skeleton branch is available remotely but not in our local Git repository. Let’s check it out.

Example

[user@localhost] $

git checkout html-skeleton
Switched to a new branch 'html-skeleton'
Branch 'html-skeleton' set up to track remote branch 'html-skeleton' from 'origin'.

And verify if it is up-to-date.

Example

[user@localhost] $

git pull
Already up to date.

What branches do we have now, and which one are we currently working on?

Example

[user@localhost] $

git branch
* html-skeleton
 master

Now, open your favorite editor and confirm that the changes from the GitHub branch are reflected.

That’s how you pull a GitHub branch into your local Git repository.