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

目录

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

一、安装Git

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

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

git

安装过则会输出:

WMBdeMacBook-Pro:~ WENBO$ 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 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、通过Xcode安装

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

二、创建ssh key、配置git

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

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

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

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

open .ssh/id_rsa.pub 

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

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

点击New SSH key,如图

添加key,如图

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

终端输出结果

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

说明已经链接成功。

三、提交本地项目到GitHub

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

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

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

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

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

cd /Users/WENBO/Desktop/

然后克隆项目,终端输入

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

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

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

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

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

然后输入:

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

终端完整输出如下:

Last login: Sat Jan   :: on ttys000
WMBdeMacBook-Pro:~ WENBO$ cd /Users/WENBO/Desktop/LearnGit
WMBdeMacBook-Pro:LearnGit WENBO$ git add .
WMBdeMacBook-Pro:LearnGit WENBO$ git commit -m "First Commit"
[master ae3bbe9] First Commit
files changed, insertions(+)
create mode LearnGitDemo/LearnGitDemo.xcodeproj/project.pbxproj
create mode LearnGitDemo/LearnGitDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
create mode LearnGitDemo/LearnGitDemo/AppDelegate.h
create mode LearnGitDemo/LearnGitDemo/AppDelegate.m
create mode LearnGitDemo/LearnGitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
create mode LearnGitDemo/LearnGitDemo/Base.lproj/LaunchScreen.storyboard
create mode LearnGitDemo/LearnGitDemo/Base.lproj/Main.storyboard
create mode LearnGitDemo/LearnGitDemo/Info.plist
create mode LearnGitDemo/LearnGitDemo/ViewController.h
create mode LearnGitDemo/LearnGitDemo/ViewController.m
create mode LearnGitDemo/LearnGitDemo/main.m
WMBdeMacBook-Pro:LearnGit WENBO$ git push
Warning: Permanently added the RSA host key for IP address '192.30.255.112' to the list of known hosts.
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), 6.80 KiB | bytes/s, done.
Total (delta ), reused (delta )
remote: Resolving deltas: % (/), done.
To github.com:wenmobo/LearnGit.git
..ae3bbe9 master -> master
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. 【SpringBoot】搜索框架ElasticSearch介绍和整合SpringBoot

    ========================12章 搜索框架ElasticSearch介绍和整合SpringBoot ============================= 加入小D课堂技术交 ...

  2. Unity外包团队:Daydream控制器只提供了3个自由度

    HTC Vive,Oculus Rift以及微软即将推出的MR头显都拥有6自由度的运动控制器,这意味着你在虚拟世界中可以任意摆动你的手.然而,Daydream控制器只提供了3个自由度,这对于手部运动具 ...

  3. Delphi IdHTTP1下载文件防止假死 (

    在Form1中添加控件:两个Indy控件:IdAntiFreeze1,IdHTTP1;一个按钮 :Button1;一个进度条 :ProgressBar1 显示下载速度 procedure TForm1 ...

  4. Redis和Memcache区别,优缺点对比

    1. Redis和Memcache都是将数据存放在内存中,都是内存数据库.不过memcache还可用于缓存其他东西,例如图片.视频等等. 2.Redis不仅仅支持简单的k/v类型的数据,同时还提供li ...

  5. oracle12建立非C##用户并且导入数据

    由于要导入dmp文件,所以想建立和oracle11一样的用户,折腾了半天,记录一下过程: 1.进入sqlplus,建立用户和分配权限 cmd>sqlplus /nolog SQL>conn ...

  6. windows下使用vscode编写运行以及调试C/C++

    未经允许,禁止转载,唯一出处:tangming博客园 最后更新于2019年4月4日: 多次更新,内容较多,篇幅较大,但如果是喜欢visual stdio code这款编辑器的话建议仔细阅读,有疑问的地 ...

  7. windows shell命令相关

    一 系统自带的命令 1 创建文件夹 mkdir 文件夹名 2 强制删除文件夹 rd/s/q 文件夹名 3 强制删除文件 del/f/s/q 文件名 4 移动文件到文件夹 move 文件名 文件夹名 二 ...

  8. 使用Python内置浏览器缓存cookies并做更新

    import requests #python内置的微型浏览器,没有界面的 #作用:缓存cookies s = requests.session() print(s.headers) #伪造请求头部, ...

  9. Spring线程池的5个要素

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-// ...

  10. JVM内存区域详解(Eden Space、Survivor Space、Old Gen、Code Cache和Perm Gen)

    JVM区域总体分两类,heap区和非heap区.heap区又分为: Eden Space(伊甸园). Survivor Space(幸存者区). Old Gen(老年代). 非heap区又分: Cod ...