通过git向gitlab上传项目代码
1.在gitlab上新建项目
不要选 ,选了以后可能报:! [rejected] master -> master (fetch first) error: failed to push some refs to ’ 。。。’
记下clone with HTTPS,
2.通过git将代码上传到gitlab上:
1)新建分支:
git branch 分支名
2)切换分支
git checkout 分支名
3)进行项目上传
git add .
git commit -m "提交的信息"
git remote add origin 远程仓库地址
此步时,使用git 添加远程github仓库的时候提示错误:fatal: remote origin already exists.
解决方案:
(1) 1、先删除远程 Git 仓库
git remote rm origin
(2)再添加远程Git仓库
git remote add origin 远程仓库地址
git push -u origin 分支名
此步可能出现2种错误:
报错1:
! [rejected] new_branch -> new_branch (fetch first)
error: failed to push some refs to ‘https://10.162.201.35:8010/zhangkaikai/jiahua_robot.git’
原因:github中的README.md文件不在本地代码目录中。
解决方案:
git push origin 分支名 -f
报错2: ! [remote rejected] new_branch -> new_branch (pre-receive hook declined) error: failed to push some refs to ‘https://10.162.201.35:8010/zhangkaikai/jiahua_robot.git’
原因是:push的分支权限为protected,只有项目的管理员或者项目的管理员指派的具有相应权限的人才能进行push,要进行项目的push,可以用下面方法:将所要push的内容所在的分支的protected权限关闭
(1)进入所在项目的settings
(2)点击进入Protected branches,点击unprotected将master分支的权限改变,即关闭master的protected权限