1.克隆项目
git clone https://gitlab.365pp.com/wechat/project_old.git
2.查看本地添加了哪些远程地址
git remote -v
// 输出结果
origin https://github.com/wechat/project_old.git (fetch)
origin https://github.com/wechat/project_old.git (push)
3.删除添加的远程仓库地址
git remote remove origin
4.添加远程仓库关联
git remote add origin https://gitlab.365pp.com/wechat/project_new.git
5.查看本地添加了哪些远程地址
git remote -v
// 输出结果 添加成功
origin https://github.com/wechat/project_new.git (fetch)
origin https://github.com/wechat/project_new.git (push)
6.将本地仓库推送到远程仓库
git push -u origin master
注意:
如果git push 时候报错
! [remote rejected] master -> master (pre-receive hook declined)
原因:权限问题,Develop角色默认下没有远程访问master的权限
解决方案:
在项目的【Setting】中的【Protected branches】可以设置哪些分支是被保护的,默认情况下【master】分支是处于被保护状态下的,develop角色的人是无法提交到master分支的,在下面的【Developers can push】打上钩就可以了。
另外使用git push --mirror可以提交本地所有分支
git push --mirror https://github.com/wechat/project_new.git
git push --mirror和git push有什么区别?
git push <origin> <master> 提交某个分支.
git push --mirror <remote-git-url> 提交所有分支.