Pulling from remotes

Intermediate Git

George Boorman

Curriculum Manager, DataCamp

Remote vs. local

local and remote branches where the remote branch has more files and subdirectories

Intermediate Git

Collaborating on Git projects

data synchronizing between five local branches and the remote branch

Intermediate Git

Fetching from a remote

  • Fetch from the origin remote
git fetch origin
  • Fetch all remote branches

  • Might create new local branches if they only existed in the remote

  • Doesn't merge the remote's contents into local repo

Intermediate Git

Fetching a remote branch

  • Fetch only from the origin remote's main branch
git fetch origin main
From https://github.com/datacamp/project
 * branch                main     -> FETCH_HEAD
Intermediate Git

Synchronizing content

  • Merge origin remote's default branch (main) into the local repo's current branch
git merge origin
Updating 9dcf4e5..887da2d
Fast-forward
 tests/tests.py | 13 +++++++++++++
 README.md     | 10 ++++++++++
 2 files changed, 23 insertions (+)
Intermediate Git

Pulling from a remote

  • Local and remote synchronization is a common workflow
  • Git simplifies this process for us!

  • Fetch and merge from the remote's default (main) into the local repo's current branch

git pull origin
Intermediate Git

Pulling a remote branch

  • Pull from the origin remote's dev branch
git pull origin dev
  • Still merges into the local branch we are located in!
Intermediate Git

Git pull output

From https://github.com/datacamp/project
 * branch                dev     -> FETCH_HEAD
Updating 9dcf4e5..887da2d
Fast-forward
 tests/tests.py | 13 +++++++++++++
 README.md     | 10 ++++++++++
 2 files changed, 23 insertions (+)
Intermediate Git

A word of caution

git pull origin
Updating 9dcf4e5..887da2d
error: Your local changes to the following files would be overwritten by merge:
       README.md
Please commit your changes or stash them before you merge.
Aborting
  • Important to save locally before pulling from a remote
Intermediate Git

Let's practice!

Intermediate Git

Preparing Video For Download...