git pull

从远程仓库拉取并合并变更到当前分支

语法

git pull [<options>] [<remote>] [<refspec>...]

参数

参数说明示例级别
--rebase 用 rebase 代替 merge 合并 git pull --rebase 常用
--no-rebase 强制使用 merge 合并 git pull --no-rebase 常用
--ff-only 只允许快进合并 git pull --ff-only 进阶
--autostash 自动暂存本地修改 git pull --rebase --autostash 进阶

示例

拉取并合并

git pull origin main
等价于 git fetch + git merge

拉取并 rebase

git pull --rebase
保持线性历史,推荐日常使用

有未提交修改时拉取

git pull --rebase --autostash
自动 stash → pull → stash pop

常见错误

CONFLICT (content): Merge conflict 手动解决冲突文件,然后 git add + git commit(merge)或 git rebase --continue(rebase)
error: cannot pull with rebase: You have unstaged changes 先 git stash 或 git commit,或加 --autostash

技巧

相关命令