美文网首页
iOS 到Github

iOS 到Github

作者: Jack__yang | 来源:发表于2016-08-24 16:08 被阅读23次

    (一.ssh的简单使用,二.push一个项目到GitHub)
    一.生成ssh

    1.首先查看当前MAC的终端有没有安装GIT

    根目录下直接输入:git
    若显示如下内容,恭喜你已经安装git,不然需要在安装一个git(这里就不细说git的安装过程)
    usage: git [--version] [--help] [-C <path>] [-c name=value]
    [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
    [-p | --paginate | --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 Forward-port local commits to the updated upstream head
    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.

    2.已知MAC上git,接下来新建SSH-key(用来和github上连接)

    终端输入: ssh-keygen -t rsa -C your@mail.com(此处填写Github上的邮箱地址)
    然后终端会显示:

    #这里以指定key例子(中间一直按Enter键)
    Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): 
    /home/git/.ssh/id_gitEnter passphrase (empty for no passphrase):
     #密码设置为空,如果设置了密码,客户端使用,需有记住此Key密码的功能
    Enter same passphrase again:
    Your identification has been saved in /tmp/id_test.
    Your public key has been saved in /tmp/id_test.pub.
    The key fingerprint is:db:c8:37:24:56:08:b8:c5:d5:8e:f3:60:84:d6:fb:a0 root@i-25BDB9AF
    The key's randomart image is:
    +--[ RSA 2048]----+
    | o.+.. |
    | . =.o.. |
    | + ..+. |
    | . B.. |
    | oS*. |
    | Eo *o |
    | + + |
    | . . |
    | |
    +-----------------+
    `到这里就已经生成完了`
    

    3.这时在终端输入:ls -a(可以查看当前所有的文件包括隐藏的,找到.ssh的文件)
    接着在终端输入:open .ssh(打开文件,找到id_rsa.pub文件打开,复制里面的文件内容)
    4.打开github点击你的头像\settings\SSH and GPG keys\New ssh key 这里的Title (可以随意写)key(把上个步骤复制的粘贴到这里)最后不要忘了Add SSH key.
    二.push 一个项目到guthub

    1.在Github上新建一个项目;
    2.终端中输入:cd 当前项目的目录
    3.终端中输入:git init (初始化)
    4.终端中输入:git add . (添加)
    5.终端中输入:git commit -m"(此处输入与你项目有关的:如XX第一次提交)"
    6.终端中输入:git remote add origin(此处填github上clone or downdload/Clone with ssh 上面的地址)

    7.终端中输入:git pull origin master
    8.终端中输入:git push origin master -f(直接推到github上)

    会显示类似如下的内容:

    Counting objects: 208, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (204/204), done.
    Writing objects: 100% (208/208), 920.10 KiB | 147.00 KiB/s, done.
    Total 208 (delta 25), reused 0 (delta 0)
    remote: Resolving deltas: 100% (25/25), done.
    To git@github.com:XXXXXXXXXXXXX
     + 53d955e...38d2198 master -> master (forced update)
    ```
    这样就已经上传成功了,可以到Github上看到你的项目了。

    相关文章

      网友评论

          本文标题:iOS 到Github

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