什么是github
GitHub是一个面向[开源]及私有[软件]项目的托管平台,因为只支持Git作为唯一的版本库格式进行托管,故名GitHub。
在这里我们将github 作为一个远程git 仓库使用,在github 你可以新建自己的代码仓库,提交,下载,管理代码。
Github 需要提前注册,网上有很多教程,这里不再赘述了。
tips: 实际在操作中发现,因为国内的某些原因,github 的连接不稳定。
git clone 的时候出现失败的问题
git clone https://github.com/tony-chenwang/source_code.git
Cloning into 'source_code'...
fatal: unable to access 'https://github.com/tony-chenwang/source_code.git/': Failed to connect to github.com port 443: Connection refused
这个时候打开github 的网页地址试试看:
https://github.com/tony-chenwang/source_code
能正常打开之后,再clone 版本仓库试试看:

创建远程代码仓库
登录到自己的github 主页
网页左上角的Repositories ==> New 进入下面的网页

-
代码仓库的名称,可以自己定义
-
代码仓库的描述,相当于对代码仓库的注释信息,会出现在下面的readme 文件中
-
该代码仓库是公开还是私有的
公开:所有人都可以下载
私人:只有自己可以下载
-
新建代码仓库的时候自带一个readme文件,作为初始化信息
-
点击创建自己的代码仓库
创建完成的代码仓库如下图:

添加修改代码,push 到远程
clone 远程仓库到本地
点击code,复制远程的代码仓库地址

在ubuntu 上clone 远程仓库
tony-chen@DESKTOP-54IDJCR:/mnt/d/Ubuntu$ git clone https://github.com/tony-chenwang/demo_repo.git
Cloning into 'demo_repo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
tony-chen@DESKTOP-54IDJCR:/mnt/d/Ubuntu$
修改文件提交到本地仓库
tony-chen@DESKTOP-54IDJCR:/mnt/d/Ubuntu/demo_repo$ git status
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
NdkImage.h
nothing added to commit but untracked files present (use "git add" to track)
git add .
git commit 添加自己的注释


push 到远程分支
tony-chen@DESKTOP-54IDJCR:/mnt/d/Ubuntu/demo_repo$ git push origin HEAD:origin/HEAD
Username for 'https://github.com': 604848340@qq.com
Password for 'https://604848340@qq.com@github.com':
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 6.39 KiB | 1.60 MiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'remotes/origin/HEAD' on GitHub by visiting:
remote: https://github.com/tony-chenwang/demo_repo/pull/new/remotes/origin/HEAD
remote:
To https://github.com/tony-chenwang/demo_repo.git
* [new branch] HEAD -> remotes/origin/HEAD
总结
我们可以用github 托管我们的代码,熟悉git 命令。
网友评论