分为三种情况:
-
创建一个全新的仓库
git clone https://gitlab.com/demo/demo.git cd demo touch README.md git add README.md git commit -m "add README" git push -u origin master
-
一个已存在的项目关联远程仓库
cd existing_folder git init git remote add origin https://gitlab.com/demo/demo.git git add . git commit -m "Initial commit" git push -u origin master
-
一个关联过git的项目关联新的远程仓库
cd existing_repo git remote rename origin old-origin git remote add origin https://gitlab.com/demo/demo.git git push -u origin --all git push -u origin --tags
有可能碰到的问题:
fatal: refusing to merge unrelated histories 原因是两个分支是两个不同的版本,具有不同的提交历史
输入命令:git pull origin master --allow-unrelated-histories
可以允许不相关历史提交,强制合并即可解决上述问题