• MAC上Git安装与GitHub使用


    目录

    • 安装git
    • 创建ssh_key、配置git
    • 提交本地项目到Github

    一、安装Git

    MAC 上安装Git主要有两种方式

    首先检查电脑是否安装Git,终端输入

    git

    安装过则会输出:

    deyou@deyoudeMacBook-Pro .ssh % git

    usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]

               [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]

               [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]

               [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]

               <command> [<args>]

    These are common Git commands used in various situations:

    start a working area (see also: git help tutorial)

       clone      Clone a repository into a new directory

       init       Create an empty Git repository or reinitialize an existing one 

    work on the current change (see also: git help everyday)

       add        Add file contents to the index

       mv         Move or rename a file, a directory, or a symlink

       reset      Reset current HEAD to the specified state

       rm         Remove files from the working tree and from the index

    examine the history and state (see also: git help revisions)

       bisect     Use binary search to find the commit that introduced a bug

       grep       Print lines matching a pattern

       log        Show commit logs

       show       Show various types of objects

       status     Show the working tree status

    grow, mark and tweak your common history

       branch     List, create, or delete branches

       checkout   Switch branches or restore working tree files

       commit     Record changes to the repository

       diff       Show changes between commits, commit and working tree, etc

       merge      Join two or more development histories together

       rebase     Reapply commits on top of another base tip

       tag        Create, list, delete or verify a tag object signed with GPG

    collaborate (see also: git help workflows)

       fetch      Download objects and refs from another repository

       pull       Fetch from and integrate with another repository or a local branch

       push       Update remote refs along with associated objects

    'git help -a' and 'git help -g' list available subcommands and some

    concept guides. See 'git help <command>' or 'git help <concept>'

    to read about a specific subcommand or concept.

    1、通过homebrew安装Git

    • 1、未安装homebrew,需安装homebrew
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    • 2、安装git
    brew install git

    2、通过安装包下载安装

      官网下载链接:https://git-scm.com/downloads

      百度网盘链接: https://pan.baidu.com/s/1fRQd_faHXbXJfjaDwdRRZQ  密码: bt1j

    二、创建SSH Key、配置Git

    • 1、设置username和email(github每次commit都会记录他们)
    git config --global user.name "DeyouKong"
    git config --global user.email "1026328997@qq.com"
    • 2、通过终端命令创建ssh key
    ssh-keygen -t rsa -C "1026328997@qq.com"
    1026328997@qq.com为我的邮箱,回车可见到一下输出

    deyou@deyoudeMacBook-Pro ~ % ssh-keygen -t rsa -C "1026328997@qq.com"

    Generating public/private rsa key pair.

    Enter file in which to save the key (/Users/deyou/.ssh/id_rsa): deyou_ssh_key

    Enter passphrase (empty for no passphrase): 

    Enter same passphrase again: 

    Your identification has been saved in deyou_ssh_key.

    Your public key has been saved in deyou_ssh_key.pub.

    The key fingerprint is:

    SHA256:qjvYDpyCL+Tbocbrh1eMlj/XO+vSBQb2g9w1b1R4eLI 1026328997@qq.com

    The key's randomart image is:

    +---[RSA 2048]----+

    |              +. |

    |       o   o = o |

    |      o = . + =  |

    |       o *   E   |

    |    +   S o .    |

    |.o = o .   .     |

    |* *+o . o .      |

    |.B++++ o +       |

    |o**o+oo o++      |

    +----[SHA256]-----+

    deyou@deyoudeMacBook-Pro ~ % ls 

    Desktop Downloads MeiCloud Music Public deyou_ssh_key.pub

    Documents Library Movies Pictures deyou_ssh_key jmeter.log

    成功的话会在~/下生成.ssh文件夹,进去,打开deyou_ssh_key.pub,复制里面的key

    终端查看deyou_ssh_key.pub文件

    cat deyou_ssh_key.pub

    3、登录GitHub(默认你已经注册了GitHub账号),添加ssh key,点击Settings,如图

    4、链接验证

    ssh -T git@github.com

    终端输出结果

    deyou@deyoudeMacBook-Pro ~ % ssh -T git@github.com
    Hi DeyouKong!You've successfully authenticated, but GitHub does not provide shell access.

    三、提交本地项目到Github

    • 1、在GitHub上新创建一个 repository或者Start a Project,填写项目信息,如图:

     

    点击Create repository,就创好一个工程了。

    • 2、提交文件

    1、仓库初始化

    git init

    2、连接仓库

    git remote add origin https://github.com/DeyouKong/httprunner.git  (更改为自己的工程地址)

    3、查看状态

    git status

    4、将文件添加到暂存区

    git add 状态里的新文件 (.为全部文件)

    5、将文件添加到仓库

    git commit -m'相关注释文字'

     6、将本地代码提交到远程仓库

    git push origin master
  • 相关阅读:
    SQL Server 2014忘记SA密码或禁用而且Windows身份验证也无法登录的解决办法
    深入解密.NET(Tuple元祖)
    DbContext 和 ObjectContext两者的区别
    开源的监控软件
    进程kswapd0与events/0消耗大量CPU的问题
    loadrunner---<二>---菜鸟对cookie的思考
    替换linux下的rm命令,并对-rf进行判断
    linux下恢复误删除的文件方法(ext2及ext3)
    oracle闪回使用以及删除存储过程恢复
    eclipse中新建maven项目-转
  • 原文地址:https://www.cnblogs.com/DeryKong/p/14137959.html
Copyright © 2020-2023  润新知