github基础的使用笔记(一):github上传项目,筛选有价值项目和下载加速

前言


  以前总是听人说,对于程序猿来讲代码管理是非常重要的,应该本科的时候就练就较好的代码管理能力。github是全球最大的代码仓库,大家肯定都在上面克隆过代码。今天假程序猿就来学习一下github的基本使用方法,包括上传项目代码到github,按需求下载项目,和下载加速,做个笔记在这里。


新建与修改


  repository /rɪˈpɑːzətɔːri/ 即仓库。填写要创建仓库的基本信息,主要就是仓库名,其他的选择性填写或者不写。创建完成之后可以直接点击upgrade file->choose your files上传本地的项目进仓库。这种方式虽然简单,但是不便于管理,所以还是要用git
  在这里插入图片描述

  从git官网上下载git工具,然后一路默认安装,安装完成后会有3个快捷方式,分别表示在GUI、CMD和Bash上进行操作。一般选择Git Bash进行操作,也可以用Git GUI,复杂度都差不多。
   在这里插入图片描述

  • 连接git与github

  生成SSH公钥

  git可以通过ssh远程连接github,需要加密,我看基本上都是选择的RSA加密算法加密的。Git Bash上输入命令: ssh-keygen -t rsa -C "[email protected]"生成ssh的由rsa加密的key到本地,其中邮箱地址是github注册邮箱。回车,回车,输入两次github登录密码,回车。然后记事本打开id_rsa.pub,复制key待用。

$ ssh-keygen -t rsa -C "[email protected]"

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/YiShu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/YiShu/.ssh/id_rsa
Your public key has been saved in /c/Users/YiShu/.ssh/id_rsa.pub
The key's randomart image is:
+---[RSA 3072]----+
|     .o X*+.     |
|      o  -.      |
|     ... .       |
|      -o. .      |
|       *S.- E    |
|      o.* + o    |
|     ...= - ...  |
|    .o =.- .= +. |
|    ..o.+ ...*+  |
+----[SHA256]-----+

  填写SSH公钥

  头像右边▼->settings->SSH and GPG keys->New SSH key。然后title随便写,key就是上一步复制的SSH public key。这样就建立了git与github的连接。
  在这里插入图片描述
  测试连接

  在Git Bash上用命令ssh -T [email protected],测试git与github的连接。第一次连接git与github会出现Are you sure you want to continue connecting (yes/no/[fingerprint])? 敲yes,回车,输入github登录密码,再回车。

$ ssh -T git@github.com

The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:hbg6kXUJWGlspRomTxdCARLviK5SY8xxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/YiShu/.ssh/id_rsa':
Hi Poetair! You've successfully authenticated, but GitHub does not provide shell access.

  • 上传文件

  Git GUI

  到需要上传项目所在的目录下,右键->Git GUI Here。在GUI上,点击clone existing repository,将github上的仓库克隆到本地。源地址,就是要往里传文件的github仓库的SSH地址:以笔者前面在github上创建的那个git_test为例,它的SSH地址:[email protected]:Poetair/git_test。目的地址随便写,我那样写表示当前目录下,git_test文件夹。然后,把要上传的内容移动到本地仓库,也就是例子中的git_test里
  在这里插入图片描述

  点击remote->add…,添加要往里传文件的github仓库的SSH地址,名字随便写。点击添加,输入密码之后,若成功会提示success
  在这里插入图片描述
  然后依次点Rescan,stage Changed,commit(添加更新描述)和push。在弹出的push界面上,点击push。输入密码之后,若成功会提示success。成功之后,打开github上的仓库,不出意外文件已经成功传上去了。注:要有更新,才能Rescan到,才会上传。
  在这里插入图片描述
  Git Bash

  进入要上传文件所在的目录,右键->Git Bash Here。在弹出的Bash窗口上,依次键入以下代码。首先,为git添加push者的信息,名字和邮箱就写github注册名和注册邮箱,设置为--global,表示所有的push都用这个信息。

git config --global user.name "your name"
git config --global user.email "[email protected]"

  直接以当前文件夹为本地仓库,用init命令初始化它。完成后会生成一个.git隐藏文件夹。

git init

  像前面GUI一样,要添加远程仓库的SSH地址。这里用remote add命令添加,test为这个SSH地址的别名,[email protected]:Poetair/git_test1.git为新建的github仓库地址。remote rm命令则是删除一个已经存在的地址。

git remote add test [email protected]:Poetair/git_test1.git

  创建一些文件,文件夹来进行测试

touch REMEME.md
mkdir src
cd src
touch test.py

  在README.md文件随意写点内容,我往里写的git test

vim REMEME.md

  把文件文件夹add到缓存。

git add src
git add REMEME.md

  commit命令用于把所做的修改保存到本地仓库,参数-m是信息的意思,一般写入此次更新的描述。

git commit -m "git test"

  将更改push到github仓库的master分支,即主分支。

git push test master

在这里插入图片描述
  上述Git Bash操作,只适合管理没有被push过的github仓库。如果仓库是在其他地方push过的(如多人协作开发时),或者原来的.git文件被损坏了,然后重新进行的上述操作。可能会出现如下错误:以在先前Git GUI上push过的git_test仓库为例。

! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘[email protected]:Poetair/git_test’
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 test master,即先从github上把仓库拉到本地,合并到master分支,然后再进行push操作就不会出现错误了。正是这样的操作,为协作开发提供了保证 。

git init
git remote add test [email protected]:Poetair/git_test
git pull --rebase test master
touch test1.py
git add test1.py
git commit -m "test1"
git push test master

在这里插入图片描述


删除


  • 删除仓库

  前面测试时创建了很多乱七八糟的仓库,现在的第一想法就是把它们删掉。可以在github上直接删除,点进仓库->setting->滑到最后的Danger Zone->Delete this repository。
在这里插入图片描述

  • 删除文件

  就在刚刚pull下来的那个仓库里操作,比如删除test1.ctest1.py,还有samples文件夹下的test.txt

git remote add test [email protected]:Poetair/git_test.git
git rm test1.c
git rm test1.py
git rm ./samples/test.txt
git commit -m "delete test.c"
$ git push test master

在这里插入图片描述


搜索项目与下载加速


  我们的项目经验不一定要通过工作获得,我们从优秀的开源项目中,也可以获取丰厚的经验。这里就做一个关于如何在github找一个热门的开源项目的笔记,来自对这个视频的学习和如何下载加速,来自与对这个视频
的学习。

  • 项目搜索

  主要的筛选因素:项目名字,项目描述,更新日期,topic,star数,fork数等。项目名字、描述定相关性;star数与fork数定火热程度。更新日期可以定其时效性。topic则描述了其关键特性。

  相关性限制:in:name VGG,即名字中含有关键词VGG的。另外还用in:readme VGGin:description VGG限定是在readme或者是在描述中含有关键词VGG。
  
  热度限制:VGG stars:>1000,即与VGG相关的,星数大于1000的。另外,还用VGG forks:>100来filter fork数。
  项目topic限制 VGG topic:pytorch ,即该项目使用深度学习框架pytorch写的。下图加框的地方就是topic。
在这里插入图片描述
  更新日期限制VGG pushed:>2019-12-12,即更新时间晚于2019年12月12日。
  语言限制VGG language:python,用python写的。

  注: 以上的限制可以并行用,更新较勤,比较热,描述详细且代码结构清晰的都是值得学习的开源项目。

  • 下载加速

  工具:码云Gitee

  随便找个项目来下载,好像太大的不行,复制该项目的地址:比如:https://github.com/qfgaohao/pytorch-ssd.打开gitee,在Repositories处点击import from Github
  在这里插入图片描述
  从URL导入,粘贴前面复制的路径在这里,import,大功告成。在码云上把项目clone到本地,就是飞一样的速度啦。注意到gitee是可以建私有仓库的,但是github上普通用户不能建私有仓库。
在这里插入图片描述


参考


  https://blog.csdn.net/jackson23333/article/details/81315474

  https://www.runoob.com/w3cnote/git-guide.html

  https://www.bilibili.com/video/BV1yJ411S7Wu

猜你喜欢

转载自blog.csdn.net/sinat_35907936/article/details/105746285