将本地项目上传到Github

简介: 下次不要再忘了虽然一直都在使用Github,但是经常不常用命令行都容易忘记掉,特意在此进行一次记录。1、在GitHub创建一个项目 2、在本地文件夹中,做一次Git初始化~/Aliyun/alioss ⌚...

下次不要再忘了

虽然一直都在使用Github,但是经常不常用命令行都容易忘记掉,特意在此进行一次记录。

1、在GitHub创建一个项目
这里写图片描述

2、在本地文件夹中,做一次Git初始化

~/Aliyun/alioss17:27:15
$ git init
Initialized empty Git repository in /Users/wangdong/Aliyun/alioss/.git/

3、将所有文件都添加到Git中

~/Aliyun/alioss onmaster! ⌚ 17:27:24
$ git add .

4、将 Git中的地址复制出来
这里写图片描述
5、本地项目和远程的GitHub关联起来

~/Aliyun/alioss onmaster! ⌚ 17:28:54
$ git remote add xiongben-tongxue https://github.com/xiongben-tongxue/alioss-demo.git

6、现在如果执行git push的话,就会报错

~/Aliyun/alioss onmaster! ⌚ 17:29:18
$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

7、那么看看状态吧

~/Aliyun/alioss on  master! ⌚ 17:31:06
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   .gitignore
    new file:   .mvn/wrapper/maven-wrapper.jar
    new file:   .mvn/wrapper/maven-wrapper.properties
    new file:   conf/log4j.properties
    new file:   mvnw
    new file:   mvnw.cmd
    new file:   pom.xml

8、需要先添加文件,再提交文件

~/Aliyun/alioss on  master! ⌚ 17:31:15
$ git add -A

~/Aliyun/alioss on  master! ⌚ 17:31:19
$ git commit -m "修复文件上传到github"
[master (root-commit) 79e296b] 修复文件上传到github
 25 files changed, 1708 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 .mvn/wrapper/maven-wrapper.jar
 create mode 100644 .mvn/wrapper/maven-wrapper.properties
 create mode 100755 conf/log4j.properties
 create mode 100755 mvnw
 create mode 100644 mvnw.cmd
 create mode 100644 pom.xml

9、再git pull一下

~/Aliyun/alioss on  master ⌚ 17:31:39
$ git pull
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/xiongben-tongxue/alioss-demo
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> master

10、分支关联

~/Aliyun/alioss onmaster17:42:35
$ git branch --set-upstream-to=origin/master master
Branch master set up to track remote branch master from origin.

11、git pull报错

~/Aliyun/alioss onmaster17:43:53
$ git pull
fatal: refusing to merge unrelated histories

12、git push报错

~/Aliyun/alioss onmaster17:49:17
$ git push
To https://github.com/xiongben-tongxue/alioss-demo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xiongben-tongxue/alioss-demo.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.

13、原因是git pull需要允许拉取在GitHub上创建的不相关联的文件

~/Aliyun/alioss onmaster17:49:43
$ git pull origin master --allow-unrelated-histories
From https://github.com/xiongben-tongxue/alioss-demo
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

14、最后再Git push 就成功了

~/Aliyun/alioss on  master ⌚ 17:50:09
$ git push
Counting objects: 52, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (52/52), 60.60 KiB | 8.66 MiB/s, done.
Total 52 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/xiongben-tongxue/alioss-demo.git
   a6023fd..b3c0fcc  master -> master
目录
相关文章
|
1月前
|
开发工具 git
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
186 69
如何操作github,gitee,gitcode三个git平台建立镜像仓库机制,这样便于维护项目只需要维护一个平台仓库地址的即可-优雅草央千澈
|
4月前
|
编解码 Oracle Java
java9到java17的新特性学习--github新项目
本文宣布了一个名为"JavaLearnNote"的新GitHub项目,该项目旨在帮助Java开发者深入理解和掌握从Java 9到Java 17的每个版本的关键新特性,并通过实战演示、社区支持和持续更新来促进学习。
133 3
|
6月前
|
存储 安全 Java
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
在一次意外中,作者因三年前将测试代码遗忘在GitHub上而遭遇了代码被他人fork的问题。为解决这一危机,作者详细介绍了如何通过GitHub的DMCA下架通知流程安全删除敏感代码,包括处理私人信息和商标侵权的具体步骤。本文不仅提供了实用的操作指南,还强调了及时响应的重要性,帮助读者避免类似风险
153 1
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
|
6月前
|
人工智能 Rust JavaScript
Github 2024-08-26 开源项目周报Top15
根据Github Trendings的统计,本周共有15个项目上榜。以下是按开发语言汇总的项目数量:Python项目8个,TypeScript、C++ 和 Rust 项目各2个,Jupyter Notebook、Shell、Swift 和 Dart 项目各1个。其中,RustDesk 是一款用 Rust 编写的开源远程桌面软件,可作为 TeamViewer 的替代品;Whisper 是一个通用的语音识别模型,基于大规模音频数据集训练而成;初学者的生成式人工智能(第2版)则是由微软提供的18门课程,教授构建生成式AI应用所需的知识。
192 1
|
6月前
|
Rust Dart 前端开发
Github 2024-08-19 开源项目周报Top15
根据Github Trendings的统计,本周(2024年8月19日统计)共有15个项目上榜。按开发语言分类,上榜项目数量如下:Python项目最多,有7项;其次是JavaScript和TypeScript,各有3项;Dart有2项;HTML、PowerShell、Clojure和C++各1项。此外,还介绍了多个热门项目,包括Bootstrap 5、RustDesk、ComfyUI、易采集、Penpot等,涵盖了Web开发、远程桌面、自动化测试、设计工具等多个领域。
147 1
|
6月前
|
JavaScript 前端开发 Go
Github 2024-08-12 开源项目周报 Top14
本周Github Trendings共有14个项目上榜,按开发语言汇总如下:Python项目7个,TypeScript项目5个,C项目2个,JavaScript项目2个,Go和Batchfile项目各1个。其中亮点包括开发者职业成长指南、Windows激活工具、ComfyUI图形界面、AFFiNE知识库、易采集可视化爬虫等项目,涵盖多种实用工具和开源平台。
233 1
|
6月前
|
SQL JavaScript 前端开发
Github 2024-08-05 开源项目周报 Top15
根据 Github Trendings 的统计,本周(2024年8月5日统计)共有15个项目上榜。以下是根据开发语言汇总的项目数量: - Go 项目:4个 - JavaScript 项目:3个 - Python 项目:3个 - Java 项目:2个 - TypeScript 项目:2个 - C 项目:1个 - Shell 项目:1个 - Dockerfile 项目:1个 - 非开发语言项目:1个
212 2
|
6月前
|
存储 JavaScript 前端开发
Github 2024-07-29 开源项目周报Top15
根据 Github Trendings 的统计,本周(2024年7月29日统计)共有15个项目上榜。按开发语言分类,项目数量如下:Python、Java、HTML 和 C 项目各有2项;TypeScript、JavaScript、Vue 和 Go 各有1项;另有1项非特定语言项目、1项 Dart 项目、1项 C++ 项目、1项 Rust 项目及1项 Jupyter Notebook 项目。这些项目涵盖了多种领域,如API开发、照片管理、PDF处理、AI技术等。
98 1
|
6月前
|
Rust JavaScript 前端开发
Github 2024-07-15 开源项目周报 Top15
根据 Github Trendings 的统计,2024年7月15日当周共有15个项目上榜。以下是按开发语言分类的项目数量汇总:Python项目5个,非开发语言项目4个,JavaScript项目3个,TypeScript项目2个,Go、Solidity和Java项目各1个,Rust项目1个。此外,介绍了多个值得关注的项目,包括免费编程学习平台 freeCodeCamp.org、免费编程书籍和学习资源清单、免费 API 集合等,涵盖了不同编程语言和技术领域。
80 1
|
6月前
|
人工智能 JavaScript API
Github 2024-07-08 开源项目周报 Top15
根据Github Trendings的统计,本周(2024年7月8日统计)共有15个项目上榜。按开发语言分类,Python项目最多,有6项;其次是C++和TypeScript,各有3项;Jupyter Notebook和JavaScript各2项;QML、非开发语言项目、Rust则各有1项。这些项目涵盖了多种领域,包括编程教育、API集合、语言模型、十六进制编辑器等。
77 1

热门文章

最新文章