The git pull
command downloads the content from a remote repository and immediately updates your local repository with the latest content. It combines the actions of git fetch
and git merge
, making it a convenient way to keep your local repository up to date.
Initial Example
$ git pull <remote_url>
PULL Options
Option | Description |
---|---|
--rebase | Rebase the current branch on top of the upstream branch after fetching. |
--no-rebase | Ensure the pull is done without rebasing. |
--no-commit | Merge fetched changes into the current branch but do not commit them. |
--no-ff | Create a merge commit even when a fast-forward merge is possible. |
--ff-only | Refuse to merge and exit unless the merge can be resolved as a fast-forward. |
--squash | Create a single commit for all the changes pulled. |
--edit | Allow editing of the commit message before committing. |
--autostash | Automatically stash local changes before pulling and reapply them afterward. |
--quiet | Suppress summary messages. |
--verbose | Provide detailed output during the pull process. |
--tags | Fetch all tags from the remote repository. |
--all | Fetch changes from all remotes. |
Examples
1. Basic Pull
This command fetches and merges changes from the main
branch of the origin
remote repository.
$ git pull origin main
2. Pull from a Specific Remote and Branch
This command fetches and merges changes from the feature-branch
branch of the specified remote repository.
$ git pull https://github.com/example/repo.git feature-branch
3. Pull with Rebase
This command fetches changes from the main
branch of the origin
remote repository and rebases your current branch on top of the fetched changes.
$ git pull --rebase origin main