将本地项目上传到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
目录
相关文章
|
9月前
|
人工智能 JavaScript 前端开发
Github 2024-10-28 开源项目周报 Top15
本周GitHub热门项目涵盖Svelte、Open Interpreter、PowerShell等,涉及Web开发、AI助手、自动化工具等领域,Python、JavaScript为主流语言,展现开源技术活跃生态。(239字)
833 19
|
9月前
|
人工智能 JavaScript 前端开发
Github 2024-11-04 开源项目周报 Top14
本周GitHub热门项目涵盖屏幕截图转代码、网页监控、低代码开发等。Python与TypeScript主导,亮点项目包括AI生成代码工具、开源社交应用Bluesky及机器人框架LeRobot,展现AI与自动化技术的快速发展趋势。
471 15
|
9月前
|
人工智能 JavaScript Docker
Github 2024-11-11 开源项目周报 Top15
本周GitHub热门项目涵盖多领域:Python与TypeScript领跑,包括屏幕截图转代码、本地文件共享、PDF处理、AI开发代理等。亮点项目如screenshot-to-code、LocalSend、OpenHands及Diagrams,兼具创新与实用性,广受开发者关注。
917 13
|
9月前
|
人工智能 算法 JavaScript
Github 2024-10-14 开源项目周报 Top14
本周GitHub热门项目共14个,Python项目占7席。涵盖算法实现、生成式AI、金融分析、目标检测等领域,包括TheAlgorithms系列、OpenBB金融平台、Ultralytics YOLO11、Manim动画框架等,展现开源技术多元发展态势。
345 8
|
9月前
|
人工智能 Rust JavaScript
Github 2024-10-07 开源项目周报 Top15
本周GitHub热门项目共15个,Python项目占比最高达7个。榜首为Python算法实现集合TheAlgorithms/Python,Star数超17万;其他亮点包括Godot游戏引擎、OpenBB金融平台、ToolJet低代码框架及新兴AI相关项目如Crawl4AI、Llama Stack等,涵盖游戏、金融、AI、理财等多个领域。
396 4
|
9月前
|
人工智能 Rust 算法
Github 2024-09-30 开源项目周报 Top15
本周GitHub热门项目揭晓:Python主导,AutoGPT居首,涵盖AI、编程、数学动画等领域,助力开发者探索前沿技术。
350 4
|
9月前
|
人工智能 JavaScript 前端开发
Github 2024-09-16 开源项目周报 Top14
本周GitHub热门项目涵盖Python、TypeScript、Go等语言,React居首。亮点包括微软PowerToys、Node版本管理器、AI证件照工具HivisionIDPhotos及端侧大模型MiniCPM等。
312 2
|
9月前
|
Rust JavaScript 安全
Github 2024-09-02 开源项目周报 Top13
本周GitHub热门项目涵盖AI、开发工具与开源替代品。包括Notion替代AppFlowy、Airtable替代NocoDB、云平台Coolify及可观察性平台OpenObserve等,涉及Python、TypeScript、Rust等语言,聚焦效率、隐私与自动化。
479 1
|
10月前
|
人工智能 编解码 JSON
不看后悔!GitHub 开源 MultiTalk .8k star 强大的人语音+图像绑定项目
MultiTalk 是 GitHub 上的开源项目,具备音频驱动、多人对话视频生成功能。支持多路音频与图像绑定,实现高同步唇动与角色互动,适用于教学、虚拟人及短视频创作,已获 8k 星标。
1103 1
|
10月前
|
安全 数据可视化 项目管理
精品,Github 5000+ star,小型研发团队必备商业开源项目
DooTask 是一款开源在线项目任务管理工具,具备文档协作、流程图、任务分发、IM沟通等功能,支持私有部署与数据加密,已在 GitHub 获得 5000+ 星标,适合中小团队提升协作效率。
838 0