1、更新遠(yuǎn)程分支
git remote update origin # 更新遠(yuǎn)程分支
git remote update origin --prune #簡化更新遠(yuǎn)程分支
2、分支查看
git branch #查看當(dāng)前本地分支
git branch -a #查看所有分支
git branch -r #查看遠(yuǎn)程origin分支
git branch master2 #創(chuàng)建新的分支
git checkout master2 #切換到新分支
git diff master…master2 #對比兩個分支的區(qū)別
git merge master2 #將master2分支合并到當(dāng)前分支
git branch -m bugfix bugfix-1 #重命名
git branch -d bugfix-1 #刪除
3、分支創(chuàng)建及推送到遠(yuǎn)程
#本地創(chuàng)建新分支,然后將該新提交到遠(yuǎn)程分支(遠(yuǎn)程以前沒有該分支)
git branch develop
git checkout develop
git add .
git commit -m "master to develop"
git push origin develop
#完結(jié)
# 創(chuàng)建新分支,并切換到該新分支
git checkout -b season2
4、分支/tag刪除
刪除本地的所有標(biāo)簽,只會刪除本地的標(biāo)簽,不會影響遠(yuǎn)程倉庫的標(biāo)簽:
git tag | xargs git tag -d
這個命令的工作原理是首先列出所有的標(biāo)簽(git tag),然后使用 xargs 命令將這些標(biāo)簽名傳遞給 git tag -d 命令,從而刪除所有的標(biāo)簽。
# git push origin --delete dev_test 刪除遠(yuǎn)程分支報錯,原因:dev_test 同名分支或tag
error: dst refspec dev_test matches more than one.
//刪除 dev_test 分支
git push origin :refs/heads/dev_test
//刪除 dev_test 標(biāo)簽
git push origin :refs/tags/dev_test
# 刪除遠(yuǎn)程分支
git push origin --delete [branch_name]
# [刪除本地分支區(qū)別
git branch -d # 會在刪除前檢查merge狀態(tài)(其與上游分支或者與head)
git branch -D # 是git branch --delete --force的簡寫,它會直接刪除
# 共同點:都是刪除本地分支的方法(與刪除遠(yuǎn)程分支命令相獨立,要想本地和遠(yuǎn)程都刪除,必須得運行兩個命令)。
# 刪除分支:
刪除本地分支 git branch -d 本地分支名
刪除遠(yuǎn)程分支 git push origin --delete 遠(yuǎn)程分支名
推送空分支到遠(yuǎn)程(刪除遠(yuǎn)程分支另一種實現(xiàn))git push origin :遠(yuǎn)程分支
# 刪除本地tag
git tag -dvTag1.0.0
# 刪除遠(yuǎn)程tag
git push --delete origin vTag1.0.0
5、git push失敗:Failed to connect to github.com port 443 after 21222 ms: Couldn't connect to server
# git push失敗:https://blog.csdn.net/m0_64007201/article/details/129628363
# fatal: unable to access 'https://github.com/xxx/xxx.git/': Failed to connect to github.com port 443 after 21222 ms: Couldn't connect to server
# 解決方案參考 https://blog.csdn.net/m0_64007201/article/details/129628363
# 解決步驟:1、查看本機網(wǎng)絡(luò)-代理-端口
# 解決步驟:2、修改git配置-代理端口,執(zhí)行下列2行命令
git config --global http.proxy http://127.0.0.1:1080(即你的代理端口)
git config --global https.proxy http://127.0.0.1:1080(即你的代理端口)
git config --global core.gitproxy http://127.0.0.1:1080(即你的代理端口)
# 解決步驟:3、繼續(xù)git push操作
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global --unset core.gitproxy
# 參考:https://blog.csdn.net/zwhfyy/article/details/130739079