git-pull
Update local branch with remote changes
TLDR
Download changes from default remote repository and merge it
Download changes from default remote repository and use fast-forward
Download changes from given remote repository and branch, then merge them into HEAD
SYNOPSIS
git pull [options] [repository [refspec...]]
Example: git pull origin main
Example: git pull --rebase
Example: git pull
PARAMETERS
--rebase
Rebase the current branch on top of the fetched branch instead of merging.
--no-rebase
Override the pull.rebase configuration, forcing a merge.
--ff-only
Refuse to merge if a fast-forward merge is not possible.
--no-ff
Create a merge commit even if a fast-forward merge is possible.
--dry-run
Show what would be done without actually making any changes.
--tags
Fetch all tags from the remote (behaves like git fetch --tags).
The name of the remote to pull from (e.g., origin). Defaults to the upstream remote configured for the current branch.
Specifies which remote branch to fetch and merge/rebase (e.g., main). If omitted, it defaults to the upstream branch configured for the current local branch.
DESCRIPTION
The git pull command is a convenient way to bring changes from a remote repository into your current local branch. It is essentially a combination of two other commands: git fetch followed by git merge.
First, git fetch downloads commits, files, and refs from the specified remote repository into your local repository without modifying your working directory. These changes are stored in remote-tracking branches (e.g., origin/main).
Second, git pull then integrates those fetched changes. By default, it performs a git merge of the remote-tracking branch into your current local branch. If a fast-forward merge is possible (meaning your local branch has no unique commits since the last pull), Git will simply move your branch pointer forward. Otherwise, it will create a new merge commit.
Alternatively, you can configure git pull to perform a git rebase instead of a merge, which replays your local commits on top of the fetched changes, resulting in a linear history. This behavior can be controlled with the --rebase option or by setting the pull.rebase configuration.
CAVEATS
- Merge Conflicts: If changes on the remote branch conflict with your local changes, git pull (when merging) will result in merge conflicts that you must resolve manually.
- Rebase Implications: Using --rebase rewrites commit history. While often preferred for a cleaner history, it should be used with caution on branches that others have already pulled, as it can cause issues for collaborators.
- Detached HEAD: Pulling on a detached HEAD will fetch, but not integrate, as there is no local branch to merge into.
- Large Repositories: In very large repositories, pulling can take significant time and consume network resources.
DEFAULT BEHAVIOR CONFIGURATION
You can configure Git to automatically use --rebase for all pulls by setting git config --global pull.rebase true. This changes the default merge behavior.
DISTINCTION FROM `GIT FETCH`
While git pull fetches and integrates, git fetch only downloads data from the remote without modifying your local working directory or current branch. This allows you to inspect remote changes before integrating them.
UPSTREAM BRANCH
By default, git pull fetches from and merges/rebases with the remote-tracking branch that your current local branch is configured to track (its "upstream"). This is often set automatically when you git clone or git branch --set-upstream-to.
HISTORY
The git pull command has been a fundamental part of Git since its early days, designed to simplify the common workflow of updating a local branch from its upstream counterpart. Initially, it was a simple wrapper script around git fetch and git merge. Over time, options like --rebase were added to accommodate different workflow preferences, allowing users to choose between a merge-based history (with merge commits) and a rebase-based linear history. Its widespread adoption reflects Git's philosophy of providing both atomic operations (fetch, merge, rebase) and convenience commands (pull) for common tasks.
SEE ALSO
git fetch(1), git merge(1), git rebase(1), git remote(1), git config(1), git push(1)