git分支常用命令

最近在用git提交代码的时候,发现有些命令不是很会,先记录几个常用分支命令,后续再补充,在执行git push命令提交代码的时候遇到报错,一并记录下。

1.git常用命令

新建分支:

复制代码
git branch <分支名称> 

比如:git branch test,创建一个test分支。

切换分支:

复制代码
git checkout <分支名称> 

比如:git checkout test,切换到test分支。

删除分支:

复制代码
git push <远程仓库别名> --delete <分支名称> 

比如:git push origin --delete test,删除远程仓库origin中的test。

合并分支:

复制代码
git merge 分支名称  (当前分支为待合并分支的主干分支,分支名称为其它待合并分支)

比如通过git branch命令查看当前分支为master,test为master的分支,想将test分支合并到master上,那么只需要执行命令:git merge test。

查看所有分支

复制代码
git branch

2.提交代码报错

在执行命令:git push -u "master"的时候,系统报错提示fatal:orgin' does not appear to be a git repository,fatal:couid not read from remote repository.",如下图所示。

解决方法:

输入以下代码,这是因为本地的分支没有和远程分支建立联系,需要执行以下代码就可以正常push了。

复制代码
git push --set-upstream origin master
相关推荐
素雨迁喜17 小时前
Linux平台下git工具的使用
linux·运维·git
Irene199119 小时前
Windows环境,VS Code 中 Git 配置指南
git·基础配置
Yang-Never20 小时前
AI Code -> Windows电脑安装Claude
开发语言·windows·git
Irene199120 小时前
2026 前端开发 Windows 安装 Git 配置指南(有实际安装过程参考:适配版本 the latest 2.53.0(2) x64 )
前端·windows·git
早起的年轻人21 小时前
告别Git仓库臃肿:一招解决Maven target目录误提交问题
java·git·maven
悠然大月季2 天前
git 怎么导出提交历史,文件是乱码
git·git导出历史记录·git导出历史乱码
chenshiming8022 天前
在cursor下执行GIT回退版本
git
打点计时器2 天前
Git快速上手教程
git
我才是一卓2 天前
linux 安装简易 git 服务端并使用
linux·运维·git
IDIOT___IDIOT2 天前
关于 git 进行版本管理的时候 gitignore 写入忽略规则而不生效的问题
大数据·git·elasticsearch