首页 > 其他分享 >使用Git上传本地项目到GitHub/Coding/码云

使用Git上传本地项目到GitHub/Coding/码云

时间:2023-05-09 20:36:06浏览次数:44  
标签:Git origin git Coding 码云 GitHub 本地 main

Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。
本文以利用Git上传本地项目到GitHub为例,为那些刚刚接触Git的新手提供使用Git上传本地项目到GitHub/Coding/码云的方法。

注册GitHub账号并安装Git

  • 首先注册GitHub账号,并添加新项目。
  • 下载并安装Git,安装路径可以自己修改,安装过程中的一些设置选择默认即可。

利用Git上传本地项目到GitHub

  • 在本地项目文件夹中空白处右键单击选择“Git Bash Here”
  • Git全局设置
$ git config --global user.name "user.name"
$ git config --global user.email "user.email"
  • 初始化Git仓库
$ git init
  • 添加文件
$ git add .

注意后面的 “.” 不要忘记写。若只想同步某一个文件,可以把 “.” 换为你要同步的 “文件名.文件类型”。如:

$ git add README.md
  • 添加注释
$ git commit -m "init"
  • 建立与远程GitHub仓库的关联
    远程仓库地址为刚才在GitHub上添加的新项目地址https://github.com/用户名/项目名.git
$ git remote add origin https://github.com/用户名/项目名.git
  • 同步到远端GitHub中新项目的分支(默认一般为main)
$ git pull origin main # 或者 master
若出现如下错误:
fatal: refusing to merge unrelated histories
可以视情况运行一下代码:
$ git pull origin main --allow-unrelated-histories  # 或者 master
  • 上传仓库到GitHub
$ git push origin main  # 或者 master

若出现如下错误:

![rejected] main -> main (non-fast-forward)

原因是远端GitHub仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。有2个解决方法:

  1. 强制覆盖,即强制用你本地的代码替代远端GitHub仓库里的内容:
$ git push --force origin main  # 或者 master
  1. 先把远端GitHub仓库中的内容fetch到本地然后merge后再push
$ git fetch
$ git merge
$ git push origin main
  • 刷新GitHub页面,搞定。

标签:Git,origin,git,Coding,码云,GitHub,本地,main
From: https://www.cnblogs.com/qiuhlee/p/17386154.html

相关文章

  • Drone CI For Github
    记录Drone标准.drone.yml文件version:"3.7"services:nginx:image:nginx:alpinecontainer_name:drone_nginxports:-"80:80"restart:alwaysnetworks:-dronenetmysql:image:mysql:5.7restart:......
  • Go源码阅读——github.com/medcl/esm —— file.go
    esm(AnElasticsearchMigrationTool)—— file.gohttps://github.com/medcl/esmrelease:8.7.1通过阅读好的源代码,细致思考,理性分析并借鉴优秀实践经验,提高zuoyang的编程水平,所谓"他山之石,可以攻玉" 该是如此吧。  /*Copyright2016Medcl(mATmedcl.net)Licen......
  • Go源码阅读——github.com/medcl/esm —— esapi.go
    esm(AnElasticsearchMigrationTool)—— esapi.go https://github.com/medcl/esmrelease:8.7.1通过阅读好的源代码,细致思考,理性分析并借鉴优秀实践经验,提高zuoyang的编程水平,所谓"他山之石,可以攻玉" 该是如此吧。 /*Copyright2016Medcl(mATmedcl.net)Licen......
  • 咚咚咚,你的王国之泪已上线「GitHub 热点速览」
    本周最大的热点,莫过于Mojo语言了,几大媒体均有报道这门兼顾Python优点和性能的新语言。当然还有凭借Switch游戏《塞尔达传说·王国之泪》登上热榜,获得3,500+star的Switch模拟器Ryujinx。当然,还有一些日常工作可能用到的测试工具gitleaks、网页加速qwik,处理数据的c......
  • Go源码阅读——github.com/medcl/esm —— bulk.go
    esm(AnElasticsearchMigrationTool)—— bulk.gohttps://github.com/medcl/esmrelease:8.7.1通过阅读好的源代码,细致思考,理性分析并借鉴优秀实践经验,提高zuoyang的编程水平,所谓"他山之石,可以攻玉" 该是如此吧。 /*Copyright2016Medcl(mATmedcl.net)Licensed......
  • GitHub搭建个人博客2023
    1.登录github2.上传一个index.html的文件3.点击settings-->然后点击pages3.选择分支->点击save ......
  • Github工具库
    0x01漏洞练习平台WebGoat漏洞练习平台:https://github.com/WebGoat/WebGoatwebgoat-legacy漏洞练习平台:https://github.com/WebGoat/WebGoat-Legacyzvuldirll漏洞练习平台:https://github.com/710leo/ZVulDrillvulapps漏洞练习平台:https://github.com/Medicean/VulApps......
  • Go源码阅读——github.com/medcl/esm —— buffer.go
    esm(AnElasticsearchMigrationTool)—— buffer.gohttps://github.com/medcl/esmrelease:8.7.1通过阅读好的源代码,细致思考,理性分析并借鉴优秀实践经验,提高zuoyang的编程水平,所谓"他山之石,可以攻玉" 该是如此吧。 /*CopyrightMedcl(mATmedcl.net)Licensedun......
  • 记录github ssh 下载代码失败解决过程
    windows机器下载airflow代码失败:[email protected]:apache/airflow.gitCloninginto'airflow'...@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@WARNING:REMOTEHOSTIDENTIFICATIONHASCHANGED!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@......
  • Go源码阅读——github.com/medcl/esm —— domain.go
    esm(AnElasticsearchMigrationTool)—— domain.gohttps://github.com/medcl/esmrelease:8.7.1通过阅读好的源代码,细致思考,理性分析并借鉴优秀实践经验,提高zuoyang的编程水平,所谓"他山之石,可以攻玉" 该是如此吧。 /*Copyright2016Medcl(mATmedcl.net)Licens......