Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools GitHub Basics Working on a Team Workflow Demonstration

Andrew Dickens
Andrew Dickens
18,352 Points

github - fetch or checkout? - video or notes wrong?

in the notes it says In this video, we used git fetch to ensure we had all the branches currently on the remote

but they don't use git fetch, Alyson only uses git checkout 'branchname'

what's the difference? if you use git checkout is it in your local repository?

and then in the following quiz it asks this question

Q: When pulling down a branch for review, what's the correct set of Git commands? A: git fetch; git checkout

Did they forget to us fetch in the video?

2 Answers

Ezra Siton
Ezra Siton
12,644 Points

When pulling down a branch for review, what's the correct set of Git commands?

In general, the text of this Q is not so clear (In the video the steps related to clone-repo with branches).

The answer:

git fetch (Downloads commits, files, and refs from a remote repository into your local repo.)
git checkout (navigate between the branches created by git branch)

Full working flow example:

A. remote (Github site)

Go to your repo Url - pencil icon (Edit) - and edit the readme file (add "hello world" text ==> Commit changes to? `create new branch" "branch-helloworld" - click "confirm"

You are now inside Open a pull request page - create pull request named "hello world pull request".

B. Local (Terminal code)

Go to your local folder.

Where is the branch?

Helper - Run: [git branch --remote: list out remote branches]

git branch --remote

You won't find branch-helloworld on the list (The remote branch From step A)

https://git-scm.com/docs/git-branch

1. Part one of the answer

Run:

git fetch

(New branch added to you local from the remote repo)

https://git-scm.com/docs/git-fetch

Run again:

git branch --remote

Now you find branch-helloworld in the list :)

2. Part two of the answer

The git checkout command lets you navigate between the branches created by git branch.

Run:

git checkout branch-helloworld

Switched to a new branch 'branch-helloworld' Branch 'branch-helloworld' set up to track remote branch 'branch-helloworld' from 'origin'.

Last step

commit changes to branch-helloworld.

Run:

git add . 
git commit -m "add change to branch-helloworld"
git push origin branch-helloworld

Go to github repo - go to branch-helloworld and you find new commit named "add change to branch-helloworld"

Chris Komaroff
PLUS
Chris Komaroff
Courses Plus Student 13,672 Points

It seems "git checkout" was used here. Teacher's notes here do not reflect video. Maybe "git fetch" or "git pull" would work. This is first example of "git checkout" I have seen that checks out files from remote repo. But a good lesson anyway.