gitlab 初始化问题

https://blog.csdn.net/maihilton/article/details/106414411

下面是你将遇到的三种情况

1. 本地创建一个新项目

git clone ssh://git@XXX/XXX/XXX.git
cd roma-doc
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2. 上传一个已存在的项目

cd existing_folder
git init
git remote add origin ssh://git@XXX/XXX/XXX.git
git add .
git commit -m "Initial commit"
git push -u origin master
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3. 上传一个已存在的git项目

cd existing_repo
git remote rename origin old-origin
git remote add origin ssh://git@XXX/XXX/XXX.git
# 由于新建的仓库是空的,所以要加上 -u 参数,第一次上传一定要加上-u参数
git push -u origin --all
git push -u origin --tags
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4. 可能出现的问题

注意这里有个很大的坑,如果创建项目的时候勾选了 Initialize this repository with a README (创建仓库的时候创建了README),执行上面的命令会报错:

failed to push some refs to 'ssh://git@XXX/XXX/XXX.git' 
  • 1

原因就是本地项目中并没有README这个文件,不同步。

# 这时需要先合并
$ git pull --rebase origin master
# 然后再 push 
$ git push -u origin master
  • 1
  • 2
原文地址:https://www.cnblogs.com/zhonghuahero/p/14080634.html