当前位置:   article > 正文

Git将本地项目推送到远程空仓库_git 把项目推送到空仓库

git 把项目推送到空仓库

前言
本文开始之前,需要先进行基础配置,将本地账户用户名 邮箱与远程git绑定。

一、创建远程仓库(码云、GitHub等)

码云仓库创建

二、进入对应项目根目录文件夹

git init // 生成.git文件
  • 1

三、将本地与远程仓库关联

 git remote add origin 远程仓库地址
  • 1

四、将本地代码推送到远程仓库

git add .
 
git commit -m '提交信息' -n
 
git push -u origin master  //第一次初始化仓库时:-u 之后不用
  • 1
  • 2
  • 3
  • 4
  • 5

五、在第四步可能出错

To https://gitee.com/all-ko/react.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/all-ko/react.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

原因:远程仓库中的README.md文件不在本地代码目录中,可以通过如下命令进行代码的合并

git pull --rebase origin master
 
//之后重复第四步最后的命令:
 
git push -u origin master  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

出现这样的代码即为成功:

$ git pull --rebase origin master
warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://gitee.com/all-ko/react
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: 首次提交
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

接着运行

git push -u origin master  
  • 1

出现这样的代码即为成功,远程推送项目代码告一段落。

$ git push -u origin master
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 8 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (16/16), 74.71 KiB | 1.36 MiB/s, done.
Total 16 (delta 0), reused 0 (delta 0)
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

最后一行代码

git push origin master //注意此刻推得分支即为想要将文件放的分支
  • 1

六、如果还是有问题:

Administrator@WIN-QTM6B4FMB6V MINGW64 /d/前端项目/webstromfiles/huaanwares (master)
$ git push --set-upstream origin master
To https://gitee.com/all-ko/huaan_statistical_software.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/all-ko/huaan_statistical_software.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

当你的代码仓库不能推送的时候,可以进行强制推送,覆盖远程仓库的内容:

 git push --set-upstream origin master -f
  • 1

推送成功代码显示如下。

 
Administrator@WIN-QTM6B4FMB6V MINGW64 /d/前端项目/webstromfiles/huaanwares (master)
$ git push --set-upstream origin master -f
Enumerating objects: 69, done.
Counting objects: 100% (69/69), done.
Delta compression using up to 4 threads
Compressing objects: 100% (59/59), done.
Writing objects: 100% (69/69), 405.77 KiB | 7.38 MiB/s, done.
Total 69 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-3.8]
To https://gitee.com/all-ko/huaan_statistical_software.git
 + ef6516a...4b29d58 master -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'origin'.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/452779
推荐阅读
相关标签
  

闽ICP备14008679号