企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
GitHub提供的Web服务,在客户端通常只需要浏览器及Git命令行工具就可以满足需要了。而GitHub还开发了一些客户端工具,以便用户有更好的客户端体验。 ## 6.3.1\. github:mac GitHub专为Mac用户开发了一款图形化客户端应用github:mac,在Mac下操作GitHub更简单。软件下载地址: [http://mac.github.com/](http://mac.github.com/) 。 github:mac 可以实现版本库克隆、查看历史、提交、分支管理、与GitHub同步等功能。图6-12展示的是提交界面,在提交界面中同时显示了变更的差异比较,用户可以挑选文件中的部分变更进行提交,显然这个操作要比在命令行中执行**git add –patch**或**git commit –patch**要更加直观。 [![../images/mac-partial-commit.png](http://www.worldhello.net/gotgithub/images/mac-partial-commit.png)](https://box.kancloud.cn/2015-07-09_559de6e25fdb3.png) 图6-12:筛选文件中的部分更改进行提交 github:mac和GitHub深度集成,当配置好关联的GitHub账号后,会自动在本地创建专用的SSH公钥/私钥对文件 ~/.ssh/github_rsa (如果该文件不存在的话),然后将公钥文件传递到GitHub网站并自动完成配置。新增的SSH公钥文件显示在GitHub网站的账号设置中,如图6-13所示: [![../images/mac-new-ssh-pubkey.png](http://www.worldhello.net/gotgithub/images/mac-new-ssh-pubkey.png)](https://box.kancloud.cn/2015-07-09_559de6f520c12.png) 图6-13:在GitHub上自动添加的SSH公钥 同时github:mac还在本地将新生成的私钥文件添加到ssh-agent认证代理中,这样一旦通过 SSH 协议连接GitHub,首先采用该公钥/私钥对进行身份认证。用下面的命令可以查看添加到ssh-agent中的私钥文件。 ~~~ $ ssh-add -l 2048 aa:01:4f:d2:14:ba:5f:9f:8c:dc:b5:9d:44:cd:8e:18 /Users/jiangxin/.ssh/github_rsa (RSA) ~~~ 这种透明的公钥认证管理非常酷,对于大多数只使用唯一一个GitHub账号的用户来说是非常方便的。但如果用户拥有多个GitHub账号并需要不时切换账号,这种实现却很糟糕,会导致认证错误。因为当ssh-agent认证代理缓存了私钥后,连接由文件~/.ssh/config 设置的 SSH 别名主机无法使用指定的公钥/私钥对进行认证,导致认证失败。 遇到 GitHub 账户 SSH 认证问题,可以运行下面命令清空ssh-agent缓存的私钥。 ~~~ $ ssh-add -d ~/.ssh/github_rsa Identity removed: /Users/jiangxin/.ssh/github_rsa (/Users/jiangxin/.ssh/github_rsa.pub) ~~~ ## 6.3.2\. hub 对于命令行用户,GitHub提供了名为hub的命令行工具,对Git进行了简单的封装。该项目在GitHub上的地址为: [https://github.com/defunkt/hub](https://github.com/defunkt/hub) 。 使用hub可以在命令行中简化对GitHub的操作。例如克隆本电子书的版本库,若用hub命令,地址可大大简化: ~~~ $ hub clone gotgit/gotgithub ~~~ 若要在自己账号下创建派生项目,无需登录GitHub网站,直接通过命令行即可实现: ~~~ $ cd gotgithub $ hub fork ~~~ 安装hub很简单,可使用如下方法任意一种方法。 * 克隆hub的版本库,从源码安装。安装步骤如下: ~~~ $ git clone git://github.com/defunkt/hub.git $ cd hub $ rake install prefix=/usr/local ~~~ * 用 RubyGems 包方式安装。 hub用 Ruby 开发,也可用 RubyGems 包方式安装。需要注意,在安装完毕后最好将hub打包为一独立运行脚本,以便运行时不再靠 RubyGems 加载,提高加载速度。安装步骤如下: ~~~ $ gem install hub $ hub hub standalone > ~/bin/hub && chmod 755 ~/bin/hub ~~~ 安装完毕后,还需要对hub进行设置。定义两个Git风格的配置变量,以便hub命令能确定当前GitHub用户账号,并能够完成所需的 GitHub API 认证。 ~~~ $ git config --global github.user "your-github-username" $ git config --global github.token "your-github-token" ~~~ 其中github.token中保存的是用户的API TOKEN,这在“2.1 创建GitHub账号”一节有过介绍。 在使用hub过程中,如果要为区分哪些命令是git的,哪些是hub的,而不断在两个命令间切换显然太不方便了。hub 命令支持以系统别名git的方式运行,即设置hub的系统别名为git,然后只需执行git命令,这样无论是git本身的命令还是hub扩展的命令都可正常运行。但要注意要用系统提供的别名方式,而不能把hub脚本改名为git,因为hub只是简单地对Git进行封装,运行时仍依赖git命令。在 bash 环境下建立别名可运行如下命令: ~~~ $ alias git=hub ~~~ 其他 shell 环境下如何建立系统别名呢?运行hub alias 命令查看相关 shell 环境下建立别名的方法。例如对于 csh: ~~~ $ hub alias csh Run this in your shell to start using `hub` as `git`: alias git hub ~~~ 下面介绍hub的常用命令,节选自hub的项目页[[1]](https://github.com/defunkt/hub#readme)。示例使用了别名命令git调用,并把对应的原始的git命令写在命令的下面(用提示符>表示,方括号中是说明)。 * git create 在GitHub上创建项目。 ~~~ $ git create -d '项目表述' > [ 在GitHub上创建版本库 ] > git remote add origin git@github.com:YOUR_USER/CURRENT_REPO.git $ git create recipes > [ 在GitHub上创建版本库 ] > git remote add origin git@github.com:YOUR_USER/recipes.git $ git create sinatra/recipes > [ 在组织账号 sinatra 下创建版本库 ] > git remote add origin git@github.com:sinatra/recipes.git ~~~ * git clone 克隆版本库可使用URL简写,即“用户名/版本库”格式地址会自动扩展为Git协议(只读)地址或SSH协议(可写)地址。 ~~~ $ git clone schacon/ticgit > git clone git://github.com/schacon/ticgit.git $ git clone -p schacon/ticgit > git clone git@github.com:schacon/ticgit.git $ git clone resque > git clone git@github.com/YOUR_USER/resque.git ~~~ * git fork 在GitHub自己账号下建立派生项目。 ~~~ $ git fork > [ 先在GitHub 上建立派生项目 ] > git remote add -f YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git ~~~ * git pull-request 打开编辑器输入标题和内容,然后在 GitHub 上创建 Pull Request。 * git remote add 设置远程版本库。和git clone命令一样支持URL简写。 ~~~ $ git remote add rtomayko > git remote add rtomayko git://github.com/rtomayko/CURRENT_REPO.git $ git remote add -p rtomayko > git remote add rtomayko git@github.com:rtomayko/CURRENT_REPO.git $ git remote add origin > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git ~~~ * git fetch 获取他人同名版本库。自动建立远程版本库并获取提交。 ~~~ $ git fetch mislav > git remote add mislav git://github.com/mislav/REPO.git > git fetch mislav $ git fetch mislav,xoebus > git remote add mislav ... > git remote add xoebus ... > git fetch --multiple mislav xoebus ~~~ * git cherry-pick 获取远程提交,并拣选至本地版本库。 ~~~ $ git cherry-pick http://github.com/mislav/REPO/commit/SHA > git remote add -f mislav git://github.com/mislav/REPO.git > git cherry-pick SHA ~~~ * git am, git apply 获取 Pull Request,并应用于本地版本库。 ~~~ $ git am https://github.com/defunkt/hub/pull/55 > curl https://github.com/defunkt/hub/pull/55.patch -o /tmp/55.patch > git am /tmp/55.patch ~~~ * git browse 打开浏览器访问相应的URL地址。 ~~~ $ git browse > open https://github.com/YOUR_USER/CURRENT_REPO $ git browse -- commit/SHA > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA $ git browse -- issues > open https://github.com/YOUR_USER/CURRENT_REPO/issues $ git browse resque > open https://github.com/YOUR_USER/resque $ git browse schacon/ticgit > open https://github.com/schacon/ticgit $ git browse schacon/ticgit commit/SHA > open https://github.com/schacon/ticgit/commit/SHA ~~~ * git help hub 查看hub命令的帮助。 ## 6.3.3\. iOS应用 GitHub还为iOS平台开发了应用,这样就可以在 iPhone、iPad 等苹果设备上实时跟踪GitHub上的项目了。在苹果AppStore上搜索GitHub公司的应用,可以找到GitHub Issues和GitHub Jobs等应用,如图6-14所示。 [![../images/ios-apps.png](http://www.worldhello.net/gotgithub/images/ios-apps.png)](https://box.kancloud.cn/2015-07-09_559de72abe08f.png) 图6-14:iPhone上的issues应用 在iPhone中安装GitHub Issues应用,就可以随时查看所关注的GitHub项目的问题报告和Pull Request等,如图6-15所示。 ![../images/ios-issues-iphone.png](https://box.kancloud.cn/2015-07-09_559de72c9fc1b.png) 图6-15:iPhone上的GitHub Issues应用 而GitHub Jobs应用则和即将要介绍的GitHub招聘网站有关,用于浏览招聘信息。