将本地vue-cli3创建的项目关联到github远程仓库

首先进入需要关联到远程仓库的项目文件夹中,执行如下命令:
1、git init
git init 初始化项目,如果是vue-cli3生成的项目,则跳过此步骤。

2、git remote add origin < remote-repository-address >
将本地的项目与远程仓库关联起来,remote-repository-address为远程仓库地址,可以去github去获取,然后执行git remote -v查看是否关联成功。

3、git add .
将项目提交到暂存区。

4、git commit -m “提交描述”
将项目提交到本地版本库。

5、git push origin master
将项目推送到远程仓库。

ps:问题来啦,当在执行第5步的时候可能会不成功,报如下错误

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/#####/vue-project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate 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 pull一下,当执行git pull origin master时,报错又来啦fatal: refusing to merge unrelated histories,意思是拒绝合并不相关的历史。查阅了下资料,可以在git pull命令后加上–allow-unrelated-histories选项,问题就迎刃而解了,
git pull origin master --allow-unrelated-histories
然后就可以愉快的git push origin master了,最后去github上刷新下看看是否有本地提交的项目。

发布了10 篇原创文章 · 获赞 0 · 访问量 1590

猜你喜欢

转载自blog.csdn.net/weixin_45266779/article/details/92828742