赞
踩
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.
1、首先复制你的git仓库的链接
2、在你的项目里面右键选择Git Bash Here打开黑窗口
3、然后输入下面的指令:
git clone xxx (xxx为刚刚复制的仓库链接)
如图:这样,我们就能将主分支的代码下载到本地了,并且自动建立了与远程仓库的连接,接下来只需要去到下载好的文件里按照以下步骤建立属于自己的分支和提交代码即可:
4、在idea中新建分支并上传代码(在此处输入指令)
(1)新建分支
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 100644 .idea/artifacts/medical_war_exploded.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/libraries/lib.xml create mode 100644 .idea/misc.xml D:\keep\IDEA\program\medical>git push origin master2 warning: redirecting to https://gitee.com/walking-201809512133/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-201809512133/git_study/pull/new/walking-201809512133:master2...walking-201809512133:m aster To http://gitee.com/walking-201809512133/git_study.git * [new branch] master2 -> master2 D:\keep\IDEA\program\medical>
参考文章:https://www.jianshu.com/p/4fe6dcdea2f5?utm_campaign
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。