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
相关推荐
.Hypocritical.21 小时前
Git 全套实操|配置 /.gitignore/ 分支合并 / 冲突解决 /git stash 完整教程
git
来日方长。。。。long21 小时前
Hermes Agent橙皮书共读|第三篇:保姆级实战部署|本地/VPS从零搭建Hermes
ide·git·hermes
其实防守也摸鱼1 天前
VS Code Git 工作树:解锁多分支并行开发新体验
数据库·git·安全·oracle·架构·自动化
ERD Online1 天前
我们怎么设计 good first issue:让第一个 PR 两小时内合入
数据库·git·后端·开源·issue
Python私教1 天前
Codex 自动写 Commit 够安全吗?一套证据化 Git 提交流程
人工智能·git·后端
果果燕1 天前
实习笔记(一):NFS、Samba、VNC、Git、CMake、systemd、内核、交叉编译
linux·arm开发·c++·笔记·git
美味蛋炒饭.1 天前
Git 版本控制(下)
开发语言·git·学习·总结·后端开发
互联网中的一颗神经元1 天前
09 — .git 地图:打开那个隐藏文件夹
大数据·git·elasticsearch
Patrick_Wilson2 天前
你知道 git check 的故事吗
git·程序员·命令行
互联网中的一颗神经元2 天前
10 — 对象模型:.git/objects 里到底装了什么
git