Git 分支操作

2023-06-02  本文已影响0人  愤斗的小蚂蚁

1、更新远程分支

git remote update origin # 更新远程分支
git remote update origin --prune #简化更新远程分支

2、分支查看

git branch  #查看当前本地分支   
git branch -a #查看所有分支   
git branch -r #查看远程origin分支 
git branch master2 #创建新的分支  
git checkout master2 #切换到新分支    
git diff master…master2 #对比两个分支的区别  
git merge master2 #将master2分支合并到当前分支    
git branch -m bugfix bugfix-1 #重命名  
git branch -d bugfix-1 #删除  

3、分支创建及推送到远程

#本地创建新分支,然后将该新提交到远程分支(远程以前没有该分支)
git branch develop
git checkout develop
git add .
git commit -m "master to develop"
git push origin develop
#完结

# 创建新分支,并切换到该新分支
git checkout -b season2

4、分支/tag删除

# git push origin --delete dev_test 删除远程分支报错,原因:dev_test 同名分支或tag
error: dst refspec dev_test matches more than one.

//删除 dev_test 分支
git push origin :refs/heads/dev_test

//删除 dev_test 标签
git push origin :refs/tags/dev_test

# 删除远程分支
git push origin --delete [branch_name]

# [删除本地分支区别
git branch -d # 会在删除前检查merge状态(其与上游分支或者与head)
git branch -D # 是git branch --delete --force的简写,它会直接删除

# 共同点:都是删除本地分支的方法(与删除远程分支命令相独立,要想本地和远程都删除,必须得运行两个命令)。

# 删除分支:
删除本地分支 git branch -d 本地分支名
删除远程分支 git push origin --delete 远程分支名
推送空分支到远程(删除远程分支另一种实现)git push origin :远程分支

# 删除本地tag
git tag -dvTag1.0.0

# 删除远程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、查看本机网络-代理-端口
# 解决步骤:2、修改git配置-代理端口,执行下列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、继续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
上一篇下一篇

猜你喜欢

热点阅读