Skip to main content

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 true

After this, git pull will be equivalent to git pull --rebase (in most ordinary cases).

To check:

bash
git config --global --get pull.rebase

Option 2: Enable rebase only in the current repository

bash
git config pull.rebase true

This 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 true

Now, 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 true

Then 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 false

Or remove the setting:

bash
git config --global --unset pull.rebase

Phrasing for an interview

Yes, you can: the pull.rebase=true setting makes git pull do a rebase instead of a merge. This can be enabled globally, per repository, or for a specific branch.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.