git新建分支及提交代码到分支

git新建分支及提交代码到分支项目场景 git 仓库中只有一个分支 且已经有上传过代码 新的代码不允许直接把你的代码覆盖上去 所以需要你掌握新建分支的方法问题描述 如果你在没有新建分支的情况下上传代码 将会报错 如下 Tohttps git oschina net erchoc laradock git rejected dev gt dev fetchfirst error failedtopush https git oschina net er

项目场景:

git仓库中只有一个分支,且已经有上传过代码,新的代码不允许直接把你的代码覆盖上去。所以需要你掌握新建分支的方法


问题描述:

如果你在没有新建分支的情况下上传代码,将会报错,如下:

To https://git.oschina.net/erchoc/laradock.git ! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'https://git.oschina.net/erchoc/laradock.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

解决方案:

2、在你的项目里面右键选择Git Bash Here打开黑窗口

3、然后输入下面的指令:

git clone xxx (xxx为刚刚复制的仓库链接) 
git branch xxx (xxx填写你的分支名称) 

(2)查看所有分支

git branch -a 

(3)切换到某一分支

git checkout xxx (xxx填写要切换的分支名称) 

(4)添加修改代码到缓存(注意最后的”.”前面有个空格)

git add . 

(5)添加提交代码的备注

git commit -m "xxx" (xxx为本次提交代码的备注) 

(6)提交代码到指定分支

git push origin xxx (xxx为要提交代码的分支名称) 

根据上述操作后成功上传项目到新的分支:

D:\keep\IDEA\program\medical>git branch master2 D:\keep\IDEA\program\medical>git branch -a * master master2 remotes/origin/HEAD -> origin/master remotes/origin/master D:\keep\IDEA\program\medical>git checkout master2 Switched to branch 'master2' D:\keep\IDEA\program\medical>git add . warning: LF will be replaced by CRLF in .idea/workspace.xml. The file will have its original line endings in your working directory warning: adding embedded git repository: git_study hint: You've added another git repository inside your current repository. D:\keep\IDEA\program\medical>git commit -m "用户权限" [master2 c6027c8] 用户权限 158 files changed, 28123 insertions(+) create mode  .idea/artifacts/medical_war_exploded.xml create mode  .idea/encodings.xml create mode  .idea/libraries/lib.xml create mode  .idea/misc.xml D:\keep\IDEA\program\medical>git push origin master2 warning: redirecting to https://gitee.com/walking-3/git_study.git/ Enumerating objects: 145, done. Counting objects: 100% (145/145), done. Delta compression using up to 8 threads Compressing objects: 100% (127/127), done. Writing objects: 100% (145/145), 4.95 MiB | 3.97 MiB/s, done. Total 145 (delta 16), reused 4 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (16/16), done. remote: Powered by GITEE.COM [GNK-5.0] remote: Create a pull request for 'master2' on Gitee by visiting: remote: https://gitee.com/walking-3/git_study/pull/new/walking-3:master2...walking-3:m aster To http://gitee.com/walking-3/git_study.git * [new branch] master2 -> master2 D:\keep\IDEA\program\medical> 

参考文章:https://www.jianshu.com/p/4fe6dcdea2f5?utm_campaign

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/217767.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 上午8:49
下一篇 2026年3月18日 上午8:49


相关推荐

  • ESLint结合gulp使用

    ESLint结合gulp使用ESLint结合gulp使用一、安装二、使用步骤1.引入库2.读入数据总结一、安装示例:pandas是基于NumPy的一种工具,该工具是为了解决数据分析任务而创建的。二、使用步骤1.引入库代码如下(示例):importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportseabornassnsimportwarningswarnings.filterwarnings(‘ignore’)im

    2022年6月18日
    28
  • python计算平均数,方差,标准差_抽样平均误差的计算

    python计算平均数,方差,标准差_抽样平均误差的计算python计算平均平方误差(MSE)的实例我们要编程计算所选直线的平均平方误差(MSE),即数据集中每个点到直线的Y方向距离的平方的平均数,表达式如下:MSE=1n∑i=1n(yi−mxi−b)2最初麻烦的写法#TODO实现以下函数并输出所选直线的MSEdefcalculateMSE(X,Y,m,b):in_bracket=[]foriinrange(len(X)):num…

    2022年9月30日
    4
  • 英特尔nuc能代替主机吗_终于圆满了!最新款的Intel NUC迷你主机上线

    近日,Intel美国官网上偷偷上线了一款全新的IntelNUC迷你主机,型号为KitNUC5PGYH,其最大的特点就是它具有完整的PC主机结构,是一台真正的PC主机,它包含有一颗PentiumN3700处理器,一条2GBDDR3L内存,32GB的eMMC闪存(嵌在主板上),一块主板。参数规格配置上,这款IntelNUC使用PentiumN3700处理器,4核心,主频2.4GHz,三级缓…

    2022年4月7日
    83
  • 直插电阻类型_假插芯和真插芯的区别

    直插电阻类型_假插芯和真插芯的区别插件电阻也称为电阻器(Resistor)在日常生活中一般直接称为电阻。是一个限流元件,将电阻接在电路中后,电阻器的阻值是固定的一般是两个引脚,它可限制通过它所连支路的电流大小。插件电阻具体讲解大全:  固定电阻、可调电阻、特种电阻(敏感电阻)  不能调节的,我们称之为定值电阻或固定电阻,而可以调节的,我们称之为可调电阻.常见的可调电阻是滑动变阻器,例如收音机音量调节的装置是个圆形的滑动…

    2022年8月21日
    7
  • QCustomPlot运用

    QCustomPlot运用日常记录学习QCustomPlot的配置和编码过程。1.结构QCustomPlot类的命名规则是QCP加xxx。类的组织有很强的区分性,就如图Qt中的模块分类。  Class Name QCPPlotTitle 图表标题 QCPAxis 坐标轴、上下左右四个坐标轴 …

    2022年10月17日
    8
  • win10安装nfs服务器并实现liunx访问「建议收藏」

    1、测试环境    宿主操作系统:win1064位    虚拟机操作系统:ubuntuserver18.042、安装nfs服务器   a.下载安装haneWIN;   b.右键以管理员身份运行nfsserver(若不以管理员身份打开,设置项均为灰色不可设),切换到“Exports”标签页,点击“Editexportsfile"进行编辑,如下图所示。比如"E:\Video"为win1…

    2022年4月13日
    741

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号