工欲善其事,必先利其器。

在OS X Yosemite 10.10.3安装最新版本号Xcode。在terminal下能够发现git已经被安装。

~ mesut$ git --version
git version 2.3.2 (Apple Git-55)

之前就已经注冊而且使用Github了,只是一直都是在window 系统下远程管理。

如今開始设置Mac管理Github,有一点须要知道的是本地的git仓库和Githubserver之间是通过ssh加密的。

在终端运行

ozil:tmp mesut$ ssh -v
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]

明显Mac已经安装了ssh。

1:创建SSH Key

ozil:tmp mesut$ cd ~
ozil:~ mesut$ pwd
/Users/mesut
ozil:~ mesut$ cd .ssh
-bash: cd: .ssh: No such file or directory
ozil:~ mesut$

进入当前的用户文件夹。波浪线表示的是当前文件夹。

推断是否已经安装了.ssh,避免默认安装会覆盖之前安装的。

明显当前文件夹没有该文件

运行创建 ssh key

ssh-keygen -t rsa -C "youremail@example.com"(你的Github登陆名)

接着都是回车,选择默认的文件夹,默认的password就可以

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mesut/.ssh/id_rsa):
Created directory '/Users/mesut/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mesut/.ssh/id_rsa.
Your public key has been saved in /Users/mesut/.ssh/id_rsa.pub.

接着能够在用户主文件夹里找到.ssh文件夹,里面有id_rsaid_rsa.pub两个文件,这两个就是SSH
Key的秘钥对

ozil:~ mesut$ cd .ssh
ozil:.ssh mesut$ ls
id_rsa id_rsa.pub

2:在Github设置ssh key

登陆Github, “Settings”->"SSH keys"->"Add SSH key"

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

title:能够顺便填名字

key:在Key文本框里粘贴id_rsa.pub文件的内容

点击add key 配置完毕

3:測试本地是否和Github连接上

史蒂夫

ozil:.ssh mesut$ ssh -T git@github.com
The authenticity of host 'github.com (xxx)' can't be established.
RSA key fingerprint is xxx.
Are you sure you want to continue connecting (yes/no)? yes

第一次链接Github,会有一个确认。须要你确认GitHub的Key的指纹信息是否真的来自GitHub的server,输入yes回车就可以。

Warning:
Permanently added 'github.com,xxx' (RSA) to the list of known hosts.Hi tanchongshi! You've successfully authenticated, but GitHub does not provide shell access.

4:使用git在本地建立的项目更新到Github

ozil:githubspace mesut$ mkdir hellogithub
ozil:githubspace mesut$ cd hellogithub/
ozil:hellogithub mesut$ ls -ah
. ..
ozil:hellogithub mesut$ git init
Initialized empty Git repository in /Users/mesut/Documents/githubspace/hellogithub/.git/
ozil:hellogithub mesut$ ls -ah
. .. .git
ozil:hellogithub mesut$ touch newfile
ozil:hellogithub mesut$ ls
newfile
ozil:hellogithub mesut$ git add newfile
ozil:hellogithub mesut$ git commit -m 'first commit'
[master (root-commit) 2295d3e] first commit
Committer: >v< <mesut@ozil.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file: git config --global --edit After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 newfile

首先在本地初始化一个git仓库

因为之前没有配置username。所以首次commit会有提示。自己主动建立

设置方式

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

为了把本地库推到远程server,首先须要在Github上面也建一个项目

在Repository name填上我们的项目名字。description随便填,别的默认。

然后会生成项目

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

然后把远程项目和本地库关联

ozil:hellogithub mesut$ git remote add origin git@github.com:tanchongshi/hellogithub.git
ozil:hellogithub mesut$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'XXX' to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 217 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:tanchongshi/hellogithub.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

https://github.com/tanchongshi/hellogithub

so far so good~


mac使用git管理Github的更多相关文章

  1. (数据科学学习手札67)使用Git管理Github仓库

    一.简介 Git是目前使用最广泛的分布式版本控制系统,通过Git可以方便高效地管理掌握工作过程中项目内容文件的更新变化情况,通过Git我们可以以命令行的形式完成对Github上开源仓库的clone,以 ...

  2. mac 设置 git 和github 告别命令行

    针对和我一样的新手,大虾们请轻拍. 很多小伙伴都想用git管理自己的代码,或者想在github上上传自己的项目.在网上找了几篇这方面的文章,都是用命令行设置的. 用命令行管理和安装太坑爹,这里有一个简 ...

  3. 使用git管理github上的项目

    使用git可以把我们的项目代码上传到github上面去,方便自己管理,如何使用git?觉得是每位程序猿所必需要有的谋生技能,所以在此记录一下自己学会使用的这个过程: 一.需要注册github账号,这样 ...

  4. mac OS git关联github

    正在更新 mac OS 默认安装了git  git -v 查看版本 mac OS 默认安装了ssh  ssh -v 查看版本 1.设置username和email(github每次commit都会记录 ...

  5. windows下使用git管理github项目

    1. 下载安装msysgithttp://code.google.com/p/msysgit/downloads/list2. 注册github账号3. 生成ssh公钥和私钥ssh-keygen -C ...

  6. 「git」mac下git提交github代码

    1.打开终端,输入 cd -/.ssh 这个是检查你的ssh的是否存在的,如果存在,先将已有的ssh备份,或者将新建的ssh生成到另外的目录下(如果第一次配置一般都是不存在的),不存在,你将会看到如下 ...

  7. 使用git管理github上的代码

    第一次接触git是使用git来提交自己的github的代码,在new repository之后,github会给出一些操作示例. 示例如下: …or create a new repository o ...

  8. mac下git连接github远程仓库

    git配置 一.安装git 官方网站下载安装,如果有安装homebrew,在终端输入brew install git,安装后的位置在/Users/计算机用户名目录下安装完成后,在终端输入git --v ...

  9. Mac下git通过SSH进行免密码安全连接github

    Git——The stupid content tracker(傻瓜内容跟踪器) Git是Linux的缔造者Linus Torvalds为了帮助管理Linux内核源码而开发的一款免费.开源的分布式版本 ...

随机推荐

  1. LaTeX的一些宏包及细节知识

    文章来源:LaTeX的一些宏包及细节知识http://blog.chinaunix.net/uid-20289887-id-1710422.html ps:我的机器上软件并不能直接运行通,下面“代码” ...

  2. Hibernate——5.2配置

    Hibernate 5.2才刚刚出来不久,很多资料都并不可靠,终于完成了Hibernate的启动,的确和Hibernate4.x有些不同. 官方文档中的代码代码会报错 如下: 目前在我所知的范围内有两 ...

  3. MySql笔记之数据表

    数据表:行称为记录  列称为字段 用来存储数据 一.数据类型 数据类型是指列.存储过程参数.表达式和局部变量的数据特征,它决定了数据的存储格式,代表了不同的信息类型. 在我们存储不同类型的数据时,为了 ...

  4. 8.1(java学习笔记)注解(Annotation)

    一.Annotation Annotation不是程序本身,但它可以对程序进行解释,这一点和注释类似. 但最大的不同点在于,注解可以被其他程序读取,然后可以对其进行一些有针对性操作. 这是注解与注释最 ...

  5. 5.9 j(java学习笔记)强软弱虚引用及WeakHashMap、IdentityHashMap、EnumMap

    一.引用分类 强:运行垃圾回收机制后也不回收,程序出现内存溢出也不回收. 软:在垃圾回收机制运行时判断内存是否已满,如果内存已满则回收,内存充足则不回收. 弱:垃圾回收机制运行后不论内存是否充足都会立 ...

  6. [Eclipse]--Error:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path.

    一段时间没用eclipse后,再去打开以前的项目,发现一打开前线标红.查看错误的时候,如下图所示: Error:The superclass "javax.servlet.http.Http ...

  7. easyui中一键清空搜索栏搜索条件的思路

    $.fn.clearAllSearchPanel = function () { var $id = $(this); $id.find(".form-control").each ...

  8. UML及其StarUML介绍

    http://blog.csdn.net/monkey_d_meng/article/details/6005764 http://www.uml.org.cn/oobject/200901203.a ...

  9. javascript中常见的函数封装 :判断是否是手机,判断是否是微信,获取url地址?后面的具体参数值,毫秒格式化时间,手机端px、rem尺寸转换等

    // 判断是否是手机function plat_is_mobile(){ var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad ...

  10. WebLogic Server 12.1.2后的字符型安装模式

    weblogic Server 12.1.1全部都可以用原来方式. WebLogic Server 12.1.2后已经取消了console安装模式,目前只有gui和静默安装模式.并且安装方式下也有很大 ...