Can git pull be configured to rebase?
Yes, you can. Git can be configured so that git pull does a rebase instead of a merge by default.
Option 1: Enable rebase for all repositories (globally)
bash
git config --global pull.rebase trueAfter this, git pull will be equivalent to git pull --rebase (in most ordinary cases).
To check:
bash
git config --global --get pull.rebaseOption 2: Enable rebase only in the current repository
bash
git config pull.rebase trueThis affects only the current project.
Option 3: Configure rebase only for a specific branch
For example, only for main:
bash
git config branch.main.rebase trueNow, when you are on main and run git pull, it will do a rebase.
A useful setting: automatically stash local changes during a rebase
If you often have uncommitted changes, this is handy:
bash
git config --global rebase.autoStash trueThen Git will automatically stash before the rebase and restore the changes afterward.
How to turn it off (go back to merge)
Globally:
bash
git config --global pull.rebase falseOr remove the setting:
bash
git config --global --unset pull.rebasePhrasing for an interview
Yes, you can: the
pull.rebase=truesetting makesgit pulldo a rebase instead of a merge. This can be enabled globally, per repository, or for a specific branch.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.