What happens by default with git pull?
By default, git pull performs two operations in a row:
git fetch + git merge
That is, Git:
- fetches the changes from the remote repository
- merges them into the current local branch via
merge
Let's break it down step by step
When you run:
bash
git pullGit does the following:
1. git fetch
- downloads new commits from the remote repository
- does not touch your working code
- updates the remote references (
origin/main,origin/dev, etc.)
2. git merge
- takes the corresponding remote branch
- merges it into the current local branch
- creates a merge commit if needed
Merge is exactly what is used by default.
Example
You are on the main branch:
bash
git pullThis is equivalent to:
bash
git fetch origin
git merge origin/mainWhat happens to the history
- the history is not rewritten
- a merge commit is possible
- if there are conflicts, Git stops and asks you to resolve them
Important point (often asked)
git pull does NOT rebase by default
If you want rebase, you need to specify it explicitly:
bash
git pull --rebaseor configure it in the config.
Short answer for an interview
By default,
git pullrunsgit fetch, thengit merge, merging the changes from the remote branch into the current local one without rewriting history.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.