Git by Example: Pull Changes
Learn how to download and integrate changes from a remote repository. This example explains how git pull combines fetching and merging to keep your code up to date.
Code
# 1. Pull changes for the current branch
git pull
# Output:
# Updating 1a2b3c..4d5e6f
# Fast-forward
# app.js | 2 ++
# 1 file changed, 2 insertions(+)
# 2. Pull from a specific remote and branch
git pull origin main
# 3. Fetch changes WITHOUT merging (safer)
git fetch origin
# 4. Pull and rebase instead of merge
git pull --rebaseExplanation
The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. It is actually a combination of two other commands: git fetch followed by git merge. First, it downloads the new data, and then it merges it into your current working branch.
Keeping your local repository up to date is crucial when working in a team. You should run git pull frequently to incorporate your teammates' work and minimize the risk of complex merge conflicts. If the remote changes can be fast-forwarded, Git will simply move your branch pointer. If there are divergent changes, Git will create a merge commit.
Some developers prefer to use git pull --rebase. Instead of creating a merge commit, this replays your local unpushed commits on top of the new remote commits. This keeps the project history linear and clean, avoiding the "diamond" shape of frequent merge commits.
- Combines
git fetchandgit merge - Updates local branch with remote changes
- Essential for team collaboration
- Can use
--rebasefor a cleaner history

