-
叨叨两句:
-
作为码农,可能我们会习惯性的在本地写
一些小demo
。而后,可能因为一些需要(比如,写的确实还不错
),想把自己在电脑上的一些小demo
,上传到github
上,方便以后的管理、更新、迭代。
-
-
做一些准备?
1. 有一个 github 账号 2. 电脑本地有 git 环境 3. 已经配置好了 git config 内容
-
如何做?步骤!
-
在自己的github帐号上,新建一个仓库
创建demo仓库.png
复制仓库地址.png
-
cd
把你要上传的demo文件夹直接拖过来
-
git init
-
git add .
-
git commit -m "xxxxxxxxxxxx"
-
git remote add origin https://自己的仓库 url 地址(上面说到的,需要复制后续用到的)
-
git push -u origin master
-
git push -u origin master
这行执行后,会出现一点问题。 -
Error :
git push -u origin master To git@github.com:xxx/xxx.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:xxx/xxx.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
-
解决办法:
$ git pull --rebase origin master // 先把远程服务器 github 上面的文件拉下来 $ git push -u origin master
-
至此,完整提交。
-
坐等所有文件上传完成后,能在自己刚创建的github仓库上看到提交的代码。
如图所示.png
-
-
关于README
-
什么是README?
-
就是一些简单的说明。比如,介绍你这个demo是什么,用来做什么,效果如何。当然,如果你写得是一个库,那可能你的README需要更详细点,比如说,你需要介绍如何使用你的库,即一个快速使用的入门指南。
-
-
在上传完代码之后,会有一个创建README的按钮。
-
创建完毕,进入到编辑界面,你可以什么都不必写。然后,点击提交到github仓库的主分支按钮。完成提交,或许,你还可以加一点提交注释。
在你的终端,cd 到这个文件夹下,git log 查看日志,然后,git pull 拉取代码。即README文件。
-
至此,你就可以在本地写代码和README了。随后的提交都会在github上看到。
-
网友评论