git 使用案例(本地仓库无缝迁移远程仓库)

之前都是直接从gitlab上clone代码,然后把本地代码copy过去,然后push。有点麻烦,查询了一下如何无缝从本地仓库迁移到远程仓库。记录一波... 

下面的例子采用github来做例子。

1. 在本地项目目下,创建本地仓库。

  cd test  // 进入项目根目录

  git init  // 初始化仓库

2. 提交代码到本地仓库

  git add *

  git commit -m "project init..."

3. 添加远程仓库

  git remote add origin https://github.com/chenkaiyin1201/null.git

  git remote -v // 可以查看一下当前项目链接的远程仓库地址

 4. push本地仓库到远程仓库

  git push origin master

 

备注:

如果出现报错

To https://github.com/chenkaiyin1201/null.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/chenkaiyin1201/null.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge the remote changes (e.g.
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 执行: git push -f 即可。

posted @ 2019-04-03 09:08  温柔了十里春冬  阅读(966)  评论(0编辑  收藏  举报