# git pull覆盖本地文件（完全舍弃本地文件）

> 这种情况比较少见，保险起见还是另外开一个新的目录从远程重新clone一份文档比较好。

有时候本地文件被搞错了，希望从远程重新同步一份代码覆盖本地文件，此时可以使用如下命令：

```
git fetch --all
```

然后有两个选项：

* 从主干同步覆盖本地文件

```
git reset --hard origin/master
```

* 从远程某个分支同步覆盖本地文件

```
git reset --hard origin/<branch_name>
```

> **`警告`**
>
> 所有本地修改的文件都会被清除

## 参考

* [How do I force “git pull” to overwrite local files?](https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/devops/git/git_pull_overwrite_local_file.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
