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
相关推荐
言之。5 小时前
Git Hooks
git
代码AI弗森6 小时前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash
森叶7 小时前
Git flow command error: ‘flow‘ is not a git command 问题解决
git
mancy_1212128 小时前
复古C语言代码复活!——以121+hello.c为例摘要
c语言·vscode·gitee·visual studio·新人首发·turbo c
天麓8 小时前
git merge 举例
git
AI_56789 小时前
Git冲突治理白皮书:智能标记与可视化协同的下一代解决方案
大数据·人工智能·git·机器学习
念丶小宇10 小时前
Git常用指令
大数据·git·elasticsearch
CSDN_RTKLIB11 小时前
Git Clone
git
中二病码农不会遇见C++学姐11 小时前
.env 文件是干啥的?为什么不能提交到 Git?
git·学习
CoderJia程序员甲12 小时前
GitHub 热榜项目 - 日榜(2026-02-03)
git·ai·开源·llm·github