新建Github仓库并上传本地代码
按照Github的教程 Adding a local repository to GitHub using Git
1. 创建空的Github仓库
创建远程仓库 ,注意不要勾选Add a README file
,如果勾选会生成一笔提交,如果本地仓库也提交了代码,会导致拉取/推送代码失败。
2. 切换到本地环境,初始化仓库
$ git init -b main
3. 添加本地文件并提交
$ git add .
# Adds the files in the local repository and stages them for commit. 若要取消暂存文件,请使用“git reset HEAD YOUR-FILE”。
$ git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. 要删除此提交并修改文件,请使用 'git reset --soft HEAD~1' 并再次提交和添加文件。
4. 关联本地仓库和远程仓库
$ git remote add origin <REMOTE_URL>
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
5. 推送代码到远程仓库
$ git push -u origin main
# Pushes the changes in your local repository up to the remote repository you specified as the origin
如果勾选了Add a README file
,执行最后一步,推送本地代码到远程仓库时会报错
error: failed to push some refs to 'github.com:bwz1984/sql2code.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 origin main
终端提示如下
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: refusing to merge unrelated histories
重点在于最后一句,Git提示fatal: refusing to merge unrelated histories
,原因分析如下
You have a new Git repository with some commits. You then try to pull from an existing remote repo. The merge becomes incompatible because the histories for branch and remote pull are different. Git sees the situation as you trying to merge two completely unrelated branches, and it doesn’t know what to do.
解决方案
$ git pull origin main --allow-unrelated-histories
$ git push origin main
新建Github仓库并上传本地代码的更多相关文章
- 在github上新建一个仓库并上传本地工程
扫盲:在github上新建一个仓库并上传本地工程 http://1ke.co/course/194 我自己新建了个项目,一步一步流程如下. zhoudd@desay:~/桌面/mini_embed_d ...
- github 仓库共享上传权限
https://blog.csdn.net/qq_33210042/article/details/79717497 打开仓库 -> Settings -> Collaborators 然 ...
- 【GIT】Github上传本地代码详解
本教程结合Github服务端和客户端完成本地代码上传至Github,下面进行详细讲解: 1.创建Github账号,这一个步骤应该不用太多解释,直接上官网进行注册登录即可https://github.c ...
- 上传本地代码及更新代码到GitHub教程
上传本地代码及更新代码到GitHub教程 上传本地代码 第一步:去github上创建自己的Repository,创建页面如下图所示: 红框为新建的仓库的https地址 第二步: echo " ...
- git配置SSH Key,上传本地代码至github
git配置全局的name和email git config --global user.name "name" git config --global user.email &qu ...
- github小白上传本地代码及更新代码到GitHub及华为云教程
上传本地代码 第一步:去github上创建自己的Repository,创建页面如下图所示: 红框为新建的仓库的https地址 第二步: echo "# Test" >> ...
- 【Hyeri】上传本地代码到Github
个人摸索出的上传本地代码到Github的办法 首先配置SSH Key(首次需要配置) 1.设置本地ssh key,打开git bash,输入命令: ssh -keygen -t rsa -C &quo ...
- mac 上传本地代码到 Github 教程
网上有很多关于windows系统上传本地代码到github的文章,但是自己用的是mac,在网上也找了相关文章,实践的过程中还是遇到了很多问题,现在把自己的成功实践分享出来,希望能对大家有帮助. 1.首 ...
- (超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库
(超详细)使用git命令行将本地仓库代码上传到github或gitlab远程仓库 本地创建了一个 xcode 工程项目,现通过 命令行 将该项目上传到 github 或者 gitlab 远程仓库,具体 ...
随机推荐
- Node.js精进(7)——日志
在 Node.js 中,提供了console模块,这是一个简单的调试控制台,其功能类似于浏览器提供的 JavaScript 控制台. 本系列所有的示例源码都已上传至Github,点击此处获取. 一.原 ...
- 面试突击62:group by 有哪些注意事项?
注意:本文以下内容基于 MySQL 5.7 InnoDB 数据库引擎. 1.group by 后面不能加 where 在 MySQL 中,所有的 SQL 查询语法要遵循以下语法顺序: select f ...
- SpringCloud微服务实战——搭建企业级开发框架(四十三):多租户可配置的电子邮件发送系统设计与实现
在日常生活中,邮件已经被聊天软件.短信等更便捷的信息传送方式代替.但在日常工作中,我们的重要的信息通知等非常有必要去归档追溯,那么邮件就是不可或缺的信息传送渠道.对于我们工作中经常用到的系统,里面 ...
- JavaScript知识梳理
JS内功修炼 专业术语 类,封装,继承, 专业术语 babel 块级作用域 函数 扩展对象的功能性 解构 set和map js的类 改进的数组功能 Promise与异步编程 代理和反射 用模块封装代码 ...
- 本地使用 Docker Compose 与 Nestjs 快速构建基于 Dapr 的 Redis 发布/订阅分布式应用
Dapr(分布式应用程序运行时)介绍 Dapr 是一个可移植的.事件驱动的运行时,它使任何开发人员能够轻松构建出弹性的.无状态和有状态的应用程序,并可运行在云平台或边缘计算中,它同时也支持多种编程语言 ...
- Map接口总结(如何使用默认方法)
Map接口总结(如何使用默认方法) Map的基本使用 默认方法的问题,有什么坑 常用的默认方法应用场景 基本操作 get put(区别:Collection接口中添加为set) putAll remo ...
- Zend Studio,php 生成报错
Zend Studio Description Resource Path Location Type Undefined CSS file ("../red-treeview.css&q ...
- 方法引用_通过this引用本类的成员方法和方法引用_类的构造器(构造方法)引用和数组的构造器引用
package com.yang.Test.ThisMethodReference; /** * 通过this引用本类的成员方法 */ public class Husband { //定义一个买房子 ...
- 云存储?不依赖三方服务自己也可以搞,利用Docker来搭建分布式文件系统FastDfs
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_78 对于文件存储来说,一般情况下简单的处理就是在Django配置文件中配置存储目录,按照规则对文件进行上传或者下载. 实际上,当文 ...
- Nginx 文件传输效率、实时、压缩配置指令
# sendfile 开启文件高效传输模式 # 默认值:off # 位置:http.servcer.location-- # 开启和不开启worker访问的文件发送到浏览器的过程不同. # 不开启的时 ...