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

在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. 使用Nginx+uWSGI部署Django项目

    1.linux安装python3环境 参考链接:https://www.cnblogs.com/zzqit/p/10087680.html 2.安装uwsgi pip3 install uwsgi l ...

  2. 【贪心】Codeforces Round #401 (Div. 2) D. Cloud of Hashtags

    从后向前枚举字符串,然后从左向右枚举位. 如果该串的某位比之前的串的该位小,那么将之前的那串截断. 如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度. 具体看代码. #include& ...

  3. 【最短路】【spfa】CODEVS 2645 Spore

    spfa最短路+判负权回路(是否某个点入队超过n次). #include<cstdio> #include<queue> #include<cstring> usi ...

  4. Bootstrap-table使用footerFormatter做统计列

    写在前面: 在做表格的时候,难免会碰到做统计的时候.由于在项目中涉及到做统计的功能比较简单,之后也就没有过多的去研究更复杂的,这里简单记录下. 这次就直接先上图:一个简单的例子 看到效果图还是很好的, ...

  5. Scala实战高手****第15课:Scala类型参数编程实战及Spark源码鉴赏

    1.Scala的类和方法.函数都可以是泛型 2.上界:表示泛型的类型必须是某种类型或者其类型的子类,语法:<: ,对类型进行限定 3.下界:表示泛型的类型必须是某种类型或者其类型的父类,语法:& ...

  6. JavaSE目录

    常识,环境变量,注释 标示符,常量,进制转换,类型转换,位运算符,语句 数组,函数 面向对象 多线程 String 包装类 集合 其他对象 IO流,IO流--FileReader&&F ...

  7. iOS开发经验——点击屏幕空白处退出键盘

          一种比较简单的点击屏幕空白处退出键盘的方法: 在ViewController中加入如下代码: 1: -(void)touchesBegan:(NSSet *)touches withEve ...

  8. Services

    *在实际运行中同样的Service的确只能有一个. Services有两种启动形式: Started:其他组件调用startService()方法启动一个Service.一旦启动,Service将一直 ...

  9. [Bug]CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temp

    win7中安装asp.net的问题 编译器错误信息: CS0016: 未能写入输出文件问题解决办法 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地 ...

  10. ArcGIS中的多个栅格波段合成一幅影像

    此处用到了ArcGIS栅格处理中的Composite Bands工具( Data Management Tools --> Raster --> Raster Processing).具体 ...