[TOC] #### 1. 前言 ---- git fetch 命令用于將遠(yuǎn)程庫更新到本地 當(dāng)遠(yuǎn)程庫中有了新的提交記錄、分支、標(biāo)簽時(shí),可以使用這個(gè)命令將遠(yuǎn)程庫中的更新拉取到本地庫;但是遠(yuǎn)程庫中的刪除標(biāo)簽、刪除分支操作比較特殊,怎么個(gè)特殊法,查看本文下面內(nèi)容即可 `git fetch` 也許你不太熟悉,但是你一定知道 `git pull`,其實(shí) `git pull` 是下面兩個(gè)命令的合集 ``` git fetch # 假設(shè)當(dāng)前在 master 分支 git merge origin/master ``` #### 2. 遠(yuǎn)程庫標(biāo)簽的更新 ---- 在遠(yuǎn)程庫中增加新的標(biāo)簽后,使用以下命令,可以將標(biāo)簽的更新操作拉取到本地庫 ``` git fetch ``` 但是,在遠(yuǎn)程庫中刪除標(biāo)簽,無法將這個(gè)刪除操作拉取到本地庫的,需要手動將本地的標(biāo)簽刪除 ``` git tag -d <tagname> ``` 我推薦使用命令刪除標(biāo)簽 ``` # 刪除本地標(biāo)簽 git tag -d <tagname> # 刪除遠(yuǎn)程庫標(biāo)簽 git push -d origin <tagname> ``` #### 3. 遠(yuǎn)程庫分支的更新 ---- 當(dāng)遠(yuǎn)程庫中出現(xiàn)了新的分支或者提交記錄,使用以下命令,可以將遠(yuǎn)程庫中的更新拉取到本地庫 ``` git fetch ```  但是,在遠(yuǎn)程庫中刪除分支后,然后在本地使用 `git fetch` 拉取,此時(shí)在本地查看遠(yuǎn)程分支時(shí)還能看到刪除的分支 ``` git fetch git branch -r ```  此時(shí),我們可以看到執(zhí)行下面這個(gè)命令查看下遠(yuǎn)程庫信息以其和本地庫的關(guān)系 ``` git remote show origin ```  通過上圖提示我們看到:可以使用下面命令移除本地的 `origin/dev` ``` git remote prune origin ``` 其實(shí)也可以使用下面這個(gè)命令移除本地的 `origin/dev` ``` git fetch --prune ```  綜上所述,我推薦使用命令刪除遠(yuǎn)程庫中的分支 ``` # 刪除已經(jīng)簽出到本地的分支 git branch -d origin <branch> # 刪除本地的 origin/<branch> 和遠(yuǎn)程庫中的分支 git push -d origin <branch> ```