美文网首页iOS基础扫盲
mac下github的使用

mac下github的使用

作者: 记忆的北极 | 来源:发表于2018-04-14 14:12 被阅读121次

    一,mac下先下载git工具, 这里链接就不上了,可以自行百度然后安装(windows的也可以下载),都是用终端命令,而不需要使用可视化工具操作.
    二,在github上创建一个新的项目库, New Repository, 如下图.

    //创建新的仓库


    75A2B390401409B247E8864621CAA7E4.jpg

    //填写信息


    F72EBD549D45BC254D287C3188C33719.jpg

    //创建完成


    D8757F55-3979-4038-A047-46E69C15ABDF.png

    三,创建ssh

    $ cd ~/.ssh若提示“-bash: cd: ~/.ssh: No such file or directory” 那就说明.ssh文件夹不存在,那么则进行下一个步骤,否则就是将原来的.ssh文件夹备份以下,亦或是切换到其他路径下建立ssh.
    也可以输入ssh-keygen -t rsa -C 715446500@qq.com (这里的为你注册Github时的邮箱账号),然后执行命令,创建ssh,执行成功后会有以下提示

    gebilaowang:~ a111$ cd /Users/a111/Desktop/project
    gebilaowang:project a111$ git init
    Initialized empty Git repository in /Users/a111/Desktop/project/.git/
    gebilaowang:project a111$ ssh-keygen -t rsa -C715446500@qq.com
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/a111/.ssh/id_rsa):  // .ssh默认路径,不输入则不修改 
    Enter passphrase (empty for no passphrase):// 密码长度至少为4,否则失败 
    Enter same passphrase again: 
    Your identification has been saved in /Users/yuyuhang/.ssh/id_rsa. 
    Your public key has been saved in /Users/yuyuhang/.ssh/id_rsa.pub. 
    

    出现以下内容就是创建成功了
    The key's randomart image is:


    1038D3987E832F6C511088405392EF91.jpg

    四,在github上添加ssh


    BE6A80897A435348070A466BF31A7262.jpg 68056767-0A70-4511-A0A2-84166E49B64D.png 49FE37F16C62E5BB3C426DB6E2D407BE.jpg

    然后打开刚才创建的ssh文件,这里去刚才默认保存的地址去查找, 找到生成的id_rsa.pub文件(/User/yourname/.ssh.is_rsa.pub)用文本打开,copy其中的内容

    B6B0A30EABBB9C1FD5CC705C632A565C.jpg image

    这串内容是在github创建ssh的时候用到的,直接把内容copy到key里就行


    9AF928D5495C83A968A4CDAA16BD2993.jpg

    //然后可以在终端cd到你要存放代码的本地文件目录下

    gebilaowang:~ a111$ ls
    AFSCSJPro               Music
    Applications                Pictures
    Desktop                 Public
    Documents               README.md
    Downloads               oppaP2rVOPTehvvadG4rc32D2Eo44g.png
    Library                 商超世界logo16*16.png
    Movies
    gebilaowang:~ a111$ pwd
    /Users/a111
    gebilaowang:~ a111$ cd Users/a11/Desktop
    -bash: cd: Users/a11/Desktop: No such file or directory
    gebilaowang:~ a111$ cd /Users/a111/Desktop
    gebilaowang:Desktop a111$ git init
    Initialized empty Git repository in /Users/a111/Desktop/.git/
    gebilaowang:Desktop a111$ cd /Users/a111/Desktop/github
    

    然后要初始化git

    gebilaowang:github a111$ git init
    Initialized empty Git repository in /Users/a111/Desktop/github/.git/
    

    然后add 添加文件到本地 并且 commit 提交到本地
    add 其中add. 可以添加全部文件

    gebilaowang:github a111$ git add AFYiTaoHuiPro
    gebilaowang:github a111$ git add AFYiTaoHuiPro.xcodeproj
    gebilaowang:github a111$ git add AFYiTaoHuiPro.xcworkspace
    gebilaowang:github a111$ git add Podfile
    gebilaowang:github a111$ git add Podfile.lock
    gebilaowang:github a111$ git add Pods
    gebilaowang:github a111$ git add README
    

    commit

    gebilaowang:github a111$ git commit -am'添加文件'
    [master (root-commit) b2ea762] 添加文件
     5856 files changed, 461875 insertions(+)
     create mode 100644 AFYiTaoHuiPro.xcodeproj/project.pbxproj
     create mode 100644 AFYiTaoHuiPro.xcodeproj/project.xcworkspace/contents.xcworkspacedata
    

    然后添加远程仓库别名

    gebilaowang:github a111$ git remote add origin git@github.com:xiaoyuanlizhi/SCSJNew.git
    gebilaowang:github a111$ git remote -v
    origin  git@github.com:xiaoyuanlizhi/SCSJNew.git (fetch)
    origin  git@github.com:xiaoyuanlizhi/SCSJNew.git (push)
    

    然后从远程分支拉流
    //需要输入刚才创建 ssh的时候的密码

    gebilaowang:github a111$ git pull origin master
    Enter passphrase for key '/Users/a111/.ssh/id_rsa': 
    

    最后git push origin master

    gebilaowang:github a111$ git push origin master
    Enter passphrase for key '/Users/a111/.ssh/id_rsa': 
    Counting objects: 6304, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (6183/6183), done.
    Writing objects: 100% (6304/6304), 181.48 MiB | 424.00 KiB/s, done.
    

    至此所有的git上传过程已经完成

    相关文章

      网友评论

        本文标题:mac下github的使用

        本文链接:https://www.haomeiwen.com/subject/pahlkftx.html