项目场景:
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
