02-Github的使用
什么是Github
GitHub 是一个面向开源及私有 软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub。
了解更多可以查看百度
前提准备
1、安装git
2、打开官网:https://github.com/
3、注册github的账号
前提准备好了就可以开始进行Git与远程仓库的连接
Github的使用
1、创建库

2、修改名字

3、删除库


1、创建文件

2、编辑文件和删除文件

创建分支

远程连接Github
1.设置用户名和邮箱
#配置git使用用户 [root@Git ~]# git config --global user.name "yanghao" #配置git使用邮箱 [root@Git ~]# git config --global user.email "123456789@163.com"
2.生成密钥(SSH key)(一直回车即可)
[root@Git python]# ssh-keygen -t rsa -C "xxxxxxxxxxx@163.com" Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 0b:f1:17:bb:4a:4b:6d:d3:7f:f2:9d:56:1c:1f:fc:18 Gboyanghao@163.com The key's randomart image is: +--[ RSA 2048]----+ | | | | | . . . | | o o E+ | | . S o +=| | . + o . =| | + = . .| | o + . ...+| | o o=o| +-----------------+
3.添加密钥(SSH key),并验证是否成功
登录github找到settings


将上一步骤生成的密钥即.ssh/id_rsa.pub中内容全部复制粘贴到上面即可
验证
[root@Git python]# ssh -T git@github.com The authenticity of host 'github.com (13.250.177.223)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts. Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.
创建项目工程
1.远程仓库:在github中New repository 输入Repository name。

2.项目工程:在自己本地电脑上新建一个与github新项目工程同名的文件夹。
[root@Git ~]# mkdir python [root@Git ~]# cd python/ [root@Git python]# git init Initialized empty Git repository in /root/python/.git/
3、远程连接仓库(两种方式)
https和ssh(这里我们就用ssh)

git remote add origin https://github.com/Gboyang/xxxxx.git git remote add origin git@github.com:Gboyang/xxxxxxxx.git //为远程Git更名为origin
4、从远程仓库pull文件(若远程仓库没有文件,直接执行步骤5)
git pull origin master
5、将本地文件push到远程仓库(若没有文件则手动创建)
git status 查看工作目录的状态 git add <file> 将文件添加到暂存区 git commit -m "commnet" 提交更改,添加备注信息(此时将暂存区的信息提交到本地仓库) git push origin master 将本地仓库的文件push到远程仓库(若 push 不成功,可加 -f 进行强推操作)
注: 至此已经完成了 远程与本地仓库的配置

浙公网安备 33010602011771号