目的:使用git推送代码至github仓库,且创立分支。

 

一.安装(步骤1)

安装git客户端

github是服务端,要想在自己电脑上使用git我们还需要一个git客户端,

windows用户请下载 http://msysgit.github.com/

二.在本地创建ssh key(步骤2)

1.使用git bash建立连接

 $ ssh-keygen -t rsa -C "your_email@youremail.com" , 如:"51102**@qq.com"

your_email@youremail.com改为你的邮箱,即是在github上注册的那个邮箱:

直接点回车--->表示无密码

使用git推送gihub方法使用教程_git

 

2.打开id_rsa.pub,全部复制

我的文件地址在:C:\Users\Administrator\.ssh

使用git推送gihub方法使用教程_github_02

使用git推送gihub方法使用教程_bash_03

 3. 回到github网站,进入Account Settings,左边选择SSH Keys,Add SSH Key,

title随便填,粘贴key。

 

使用git推送gihub方法使用教程_git_04

      

使用git推送gihub方法使用教程_bash_05

4.验证是否成功,在git bash下输入

$ ssh -T git@github.com 

You’ve successfully authenticated, but GitHub does not provide shell access ,表示已成功连上github。

使用git推送gihub方法使用教程_github_06

5. 设置邮箱与名称

a.设置名称:

$ git config --global user.name "your name"

b.设置邮箱

$ git config --global user.email "your_email@youremail.com"

github每次commit都会记录他们。

使用git推送gihub方法使用教程_bash_07

 

三.创建github仓库(步骤3)

1.github创建仓库

使用git推送gihub方法使用教程_git_08

2.获得仓库地址

使用git推送gihub方法使用教程_git_09

四.使用git上传代码至github仓库中(步骤4)

要上传的文件夹,右击使用git bash。

1.进入要上传的仓库,右键git bash,添加远程地址

$ git remote add origin git@github.com:yourName/yourRepo.git 后面的yourName和yourRepo表示你再github的用户名和刚才新建的仓库,加完之后进入.git。

使用git推送gihub方法使用教程_github_10

 2.执行过git init之后可以看到文件夹中多了个.git文件目录。

$ git init

 

3.push代码,使用git提交代码的三部曲,add,commit,push

$ git add .

 

使用git推送gihub方法使用教程_github_11

 

$ git commit -m 'first commit'

使用git推送gihub方法使用教程_git_12

 

$ git push origin master

使用git推送gihub方法使用教程_git_13

 

结果如下:

使用git推送gihub方法使用教程_git_14

 

五.使用tag方法

1.tags与branch介绍

  在 GitHub 中,Branches(分支)和 Tags(标签)都是用于版本控制的重要工具。Branches(分支)可创建一个新的开发分支,允许在不影响主分支的情况下对代码进行修改和实验,且可允许多个开发者在同一个代码库中开发和测试代码,而不干扰彼此。每个分支都有自己的代码提交历史和版本控制记录,可以随时合并到主分支中。Tags(标签)则用于标记代码库中的一个特定版本,标签是一个静态的版本,不可修改,标签通常用于版本发布,比如在发布软件的时候,可以给某一版本打上标签,作为该软件的版本号。

2.创建tag与push

a.创建tag

$ git push origin tag_name  -m  "注释说明"  ,如:$git tag v1.0 -m "v1.0版本"

使用git推送gihub方法使用教程_bash_15

 b.推送

$ git push origin v1.0

使用git推送gihub方法使用教程_github_16

 c.删除tag

$ git push origin --delete Tag名

最终结果显示:

使用git推送gihub方法使用教程_github_17