转自:https://www.jianshu.com/p/7edb6b838a2e

目录

  • 安装git
  • 创建ssh key、配置git
  • 提交本地项目到GitHub

一、安装Git

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

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

  1. git

安装过则会输出:

  1. WMBdeMacBook-Pro:~ WENBO$ git
  2. usage: git [--version] [--help] [-C <path>] [-c name=value]
  3. [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
  4. [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
  5. [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
  6. <command> [<args>]
  7.  
  8. These are common Git commands used in various situations:
  9.  
  10. start a working area (see also: git help tutorial)
  11. clone Clone a repository into a new directory
  12. init Create an empty Git repository or reinitialize an existing one
  13.  
  14. work on the current change (see also: git help everyday)
  15. add Add file contents to the index
  16. mv Move or rename a file, a directory, or a symlink
  17. reset Reset current HEAD to the specified state
  18. rm Remove files from the working tree and from the index
  19.  
  20. examine the history and state (see also: git help revisions)
  21. bisect Use binary search to find the commit that introduced a bug
  22. grep Print lines matching a pattern
  23. log Show commit logs
  24. show Show various types of objects
  25. status Show the working tree status
  26.  
  27. grow, mark and tweak your common history
  28. branch List, create, or delete branches
  29. checkout Switch branches or restore working tree files
  30. commit Record changes to the repository
  31. diff Show changes between commits, commit and working tree, etc
  32. merge Join two or more development histories together
  33. rebase Reapply commits on top of another base tip
  34. tag Create, list, delete or verify a tag object signed with GPG
  35.  
  36. collaborate (see also: git help workflows)
  37. fetch Download objects and refs from another repository
  38. pull Fetch from and integrate with another repository or a local branch
  39. push Update remote refs along with associated objects
  40.  
  41. 'git help -a' and 'git help -g' list available subcommands and some
  42. concept guides. See 'git help <command>' or 'git help <concept>'
  43. to read about a specific subcommand or concept.

1、通过homebrew安装Git

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

2、通过Xcode安装

直接从AppStore安装Xcode,Xcode集成了Git,不过默认没有安装,你需要运行Xcode,选择菜单“Xcode”->“Preferences”,在弹出窗口中找到“Downloads”,选择“Command Line Tools”,点“Install”就可以完成安装了。

二、创建ssh key、配置git

  • 1、设置username和email(github每次commit都会记录他们)
  1. git config --global user.name "wenbo"
  2. git config --global user.email "1050794513@qq.com"
  • 2、通过终端命令创建ssh key
  1. ssh-keygen -t rsa -C "1050794513@qq.com"

1050794513@qq.com是我的邮件名,回车会有以下输出

  1. Last login: Sat Jan :: on ttys000
  2. WMBdeMacBook-Pro:~ WENBO$ ssh-keygen -t rsa -C "1050794513@qq.com"
  3. Generating public/private rsa key pair.
  4. Enter file in which to save the key (/Users/WENBO/.ssh/id_rsa):
  5. /Users/WENBO/.ssh/id_rsa already exists.
  6. Overwrite (y/n)? n
  7. WMBdeMacBook-Pro:~ WENBO$

由于这里我原来已经创建过,这里我选n,没有创建过的,会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
终端查看.ssh/id_rsa.pub文件

  1. open .ssh/id_rsa.pub

回车后,就会新弹出一个终端,然后复制里面的key。
或者用cat命令查看

  1. cat .ssh/id_rsa.pub
  • 3、登录GitHub(默认你已经注册了GitHub账号),添加ssh key,点击Settings,如图

点击New SSH key,如图

添加key,如图

  • 4、链接验证
  1. ssh -T git@github.com

终端输出结果

  1. Last login: Sat Jan :: on ttys000
  2. WMBdeMacBook-Pro:~ WENBO$ ssh -T git@github.com
  3. Hi wenmobo! You've successfully authenticated, but GitHub does not provide shell access.
  4. WMBdeMacBook-Pro:~ WENBO$

说明已经链接成功。

三、提交本地项目到GitHub

  • 1、在GitHub上新创建一个 repository或者Start a Project,如图:

  • 2、填写项目信息,如下图所示:

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

  • 3、Clone工程到本地,首先复制ssh 地址

打开终端,这里只是测试,我想把工程克隆在桌面,首先在终端中切换路径到桌面,输入以下命令:

  1. cd /Users/WENBO/Desktop/

然后克隆项目,终端输入

  1. git clone git@github.com:wenmobo/LearnGit.git

git@github.com:wenmobo/LearnGit.git是刚刚复制的ssh路径。
终端完整输出如下:

  1. Last login: Sat Jan :: on ttys000
  2. WMBdeMacBook-Pro:~ WENBO$ cd /Users/WENBO/Desktop/
  3. WMBdeMacBook-Pro:Desktop WENBO$ git clone git@github.com:wenmobo/LearnGit.git
  4. Cloning into 'LearnGit'...
  5. remote: Counting objects: , done.
  6. remote: Compressing objects: % (/), done.
  7. remote: Total (delta ), reused (delta ), pack-reused
  8. Receiving objects: % (/), 5.2

  • 4、在Xcode中新创建一个工程,保存的路径为刚刚克隆下来的LearnGit文件夹下,如下图所示:

  • 5、提交修改,首先切换到LearnGit文件路径:
  1. cd /Users/WENBO/Desktop/LearnGit

然后输入:

  1. //文件添加到仓库(.代表提交所有文件)
  2. git add .
  3. //把文件提交到仓库
  4. git commit -m "First Commit"
  5. //上传到github
  6. git push

终端完整输出如下:

  1. Last login: Sat Jan :: on ttys000
  2. WMBdeMacBook-Pro:~ WENBO$ cd /Users/WENBO/Desktop/LearnGit
  3. WMBdeMacBook-Pro:LearnGit WENBO$ git add .
  4. WMBdeMacBook-Pro:LearnGit WENBO$ git commit -m "First Commit"
  5. [master ae3bbe9] First Commit
  6. files changed, insertions(+)
  7. create mode LearnGitDemo/LearnGitDemo.xcodeproj/project.pbxproj
  8. create mode LearnGitDemo/LearnGitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  9. create mode LearnGitDemo/LearnGitDemo/AppDelegate.h
  10. create mode LearnGitDemo/LearnGitDemo/AppDelegate.m
  11. create mode LearnGitDemo/LearnGitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
  12. create mode LearnGitDemo/LearnGitDemo/Base.lproj/LaunchScreen.storyboard
  13. create mode LearnGitDemo/LearnGitDemo/Base.lproj/Main.storyboard
  14. create mode LearnGitDemo/LearnGitDemo/Info.plist
  15. create mode LearnGitDemo/LearnGitDemo/ViewController.h
  16. create mode LearnGitDemo/LearnGitDemo/ViewController.m
  17. create mode LearnGitDemo/LearnGitDemo/main.m
  18. WMBdeMacBook-Pro:LearnGit WENBO$ git push
  19. Warning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.
  20. Counting objects: , done.
  21. Delta compression using up to threads.
  22. Compressing objects: % (/), done.
  23. Writing objects: % (/), 6.80 KiB | bytes/s, done.
  24. Total (delta ), reused (delta )
  25. remote: Resolving deltas: % (/), done.
  26. To github.com:wenmobo/LearnGit.git
  27. ..ae3bbe9 master -> master
  28. WMBdeMacBook-Pro:LearnGit WENBO$

查看GitHub上的项目,已经上传成功啦,如下图所示:

【mac上安装&配置&使用git】的更多相关文章

  1. Mac上安装配置Go语言,其实很简单(一)

    下载Go语言可以去:Go语言中文网 安装及自己选择是否修改GOPATH 下载下来后双击安装就好,使用 go version 查看安装版本: 在Mac上安装完成后,会自动设置一些环境变量,使用 go e ...

  2. Mac上安装配置和简单使用PostgreSQL(仍然很不懂)

    因为想要使用推荐的rails-template.需要使用postgres.并初始化了一个用户postgres,密码是postgres.( e.g. $ createuser -d postgres ) ...

  3. 在Mac上安装mysql并配置环境(详细篇)

    在Mac上安装mysql并配置环境(详细篇) 1.下载mysql mysql官网 这一步根据自己电脑架构选择,分为arm和x86 下载完成之后打开就可以 接下来运行安装就可以,一直下一步,设置完密码就 ...

  4. mac上一键配置和安装adb驱动或者环境

    最近才使用的mac,老实说mac上要配置adb的环境不那么复杂,但是还是会让一些心不细或者动手能力不强的同学望而却步.那么到底有没有一个一键完成mac上adb和fastboot环境搭配的软件或者脚本呢 ...

  5. Mac上安装Charles进行抓包全流程设置

    安装 -- 官网下载最新版的Charles版本,按照提示安装即可 破解 -- https://blog.csdn.net/qq_25821067/article/details/79848589. M ...

  6. 002-docker安装-mac上安装docker,17.06在CentOS7 64位机器上安装

    一.mac上安装docker 1.下载 通过这个链接下载:https://download.docker.com/mac/stable/Docker.dmg 2.安装 将 Moby 的鲸鱼图标拖拽到  ...

  7. MAC上ITERM2配置SZ, RZ远程上传和下载文件

    MAC上ITERM2配置SZ, RZ远程上传和下载文件 From article 在Windows上的SecureCRT.XShell远程连接Linux服务器,通常可以使用sz.rz等命令来上传和下载 ...

  8. Mac下安装配置NMP环境

    第一次在Mac上安装NMP,记录下 因为下面环境的安装都是基于homebrew的,所以如果没有安装他的话,要先安装他(官网:https://brew.sh/index_zh-cn.html) 安装ho ...

  9. Mac上安装Grafana

    Mac上安装Grafana 一.背景 二.安装步骤 1.通过 Home Brew 安装 2.通过二进制包进行安装 1.下载 2.grafana配置文件的路径 3.修改grafana配置 1.修改默认的 ...

随机推荐

  1. hsdfz -- 6.17 -- day2

    今日依旧康复…… 当天晚上被老师拉去小吃街了,晚上回来精力憔悴,所以并没有当天写 反正就惨,因为估错复杂度,期望得分100分最后结果20分 (我的复杂度是nlog^2n的,正确性有保障,稳! 事后:还 ...

  2. oracle-logminer

    LogMiner工具实际上是由两个新的PL/SQL内建包((DBMS_LOGMNR 和 DBMS_ LOGMNR_D)和四个V$动态性能视图(视图是在利用过程DBMS_LOGMNR.START_LOG ...

  3. qsort函数排序各种类型的数据。

    qsort函数是库函数中的一员,我们先来看看官方文档是怎么写的: 其中qsort的参数void* base是传入一个数组,size_t num 为数组整体大小,size_t size 为单个元素的大小 ...

  4. Excel技巧--反向查询

    当要从左侧的表格,查询某人所在的部门时,那么需要逆向查询.VLOOKUP函数只能正向查询.可以使用Match和index函数: Match函数:查询某个值在指定区域所在的位置: Index函数:查询指 ...

  5. Sonar6.7.1配置修改备注

    sonarqube-6.7.1\conf\sonar.properties的配置字段 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useU ...

  6. Markdown语法说明(转)

    Markdown语法说明(转) Markdown创始人John Gruber的语法说明 附上本文链接 NOTE: This is Simplelified Chinese Edition Docume ...

  7. php语法基础(相比C语言)

    前言 php的语法跟C语言很类似,相信有一定C的基础的人学起来会非常快. 本篇主要介绍php相比C语言有差异的地方 php代码标记 ASP标记:<% 代码 %> 短标记:<? 代码 ...

  8. nginx http转 https

    场景 项目前期使用http,后期为了安全方面的考虑,启用了https.项目架构:前端使用nginx作为多个tomcat实例的反向代理和负载均衡.实际上只需要在nginx上启用https即可,使客户端与 ...

  9. PAT 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  10. 廖雪峰Java6 IO编程-3Reader和Writer-1Reader

    1.java.io.Reader和java.io.InputStream的区别 InputStream Reader 字节流,以byte为单位 字符流,以char为单位 读取字节(-1,0-255): ...