将本地项目上传到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月前
|
人工智能 文字识别 异构计算
关于github开源ocr项目的疑问
小白尝试Python OCR学习,遇到报错。尝试Paddle OCR部署失败,Tesseract OCR在Colab误操作后恢复失败。EasyOCR在Colab和阿里天池Notebook成功,但GPU资源不足。其他平台部署不顺,决定使用WebUI或阿里云轻应用。求教OCR项目部署到本地及简单OCR项目推荐。
29 2
|
1月前
|
人工智能 自然语言处理 iOS开发
『GitHub项目圈选19』推荐5款本周 让人爱不释手 的开源项目
『GitHub项目圈选19』推荐5款本周 让人爱不释手 的开源项目
|
1月前
|
存储 Web App开发 人工智能
『GitHub项目圈选18』推荐5款本周 超实用 的开源项目
『GitHub项目圈选18』推荐5款本周 超实用 的开源项目
|
1月前
|
人工智能 物联网 机器人
『GitHub项目圈选17』推荐5款本周 火火火 的AI开源项目
『GitHub项目圈选17』推荐5款本周 火火火 的AI开源项目
194 1
|
1月前
|
JSON 搜索推荐 程序员
『GitHub项目圈选15』推荐5款本周 深受程序员喜爱 的开源项目
『GitHub项目圈选15』推荐5款本周 深受程序员喜爱 的开源项目
|
1月前
|
人工智能 自然语言处理 NoSQL
『GitHub项目圈选13』推荐5款本周 让人爱不释手 的开源项目
『GitHub项目圈选13』推荐5款本周 让人爱不释手 的开源项目
|
1月前
|
SQL NoSQL Linux
『GitHub项目圈选11』推荐5款本周 深受开发人员青睐 的开源项目
『GitHub项目圈选11』推荐5款本周 深受开发人员青睐 的开源项目
|
1月前
|
存储 人工智能 API
『GitHub项目圈选10』推荐5款本周 实用给力 的开源项目
『GitHub项目圈选10』推荐5款本周 实用给力 的开源项目
|
1月前
|
自然语言处理 Cloud Native 前端开发
『GitHub项目圈选16』推荐5款本周 大佬狂爱 的开源项目
『GitHub项目圈选16』推荐5款本周 大佬狂爱 的开源项目
|
1月前
|
人工智能 文字识别 自然语言处理
『GitHub项目圈选12』推荐5款本周 深受追捧 的AI开源项目
『GitHub项目圈选12』推荐5款本周 深受追捧 的AI开源项目
167 1