README.md 10.8 KB
Newer Older
M
Mislav Marohnić 已提交
1 2
git + hub = github
==================
C
readme  
Chris Wanstrath 已提交
3

M
Mislav Marohnić 已提交
4 5
hub is a command line tool that wraps `git` in order to extend it with extra
features and commands that make working with GitHub easier.
C
readme  
Chris Wanstrath 已提交
6

M
Mislav Marohnić 已提交
7 8
~~~ sh
$ hub clone rtomayko/tilt
C
readme  
Chris Wanstrath 已提交
9

M
Mislav Marohnić 已提交
10 11 12
# expands to:
$ git clone git://github.com/rtomayko/tilt.git
~~~
C
Chris Wanstrath 已提交
13

M
Mislav Marohnić 已提交
14 15
hub is best aliased as `git`, so you can type `$ git <command>` in the shell and
get all the usual `hub` features. See "Aliasing" below.
C
tweak  
Chris Wanstrath 已提交
16

C
Chris Wanstrath 已提交
17

M
Mislav Marohnić 已提交
18 19
Installation
------------
C
Chris Wanstrath 已提交
20

M
Mislav Marohnić 已提交
21
Dependencies:
C
Chris Wanstrath 已提交
22

M
Mislav Marohnić 已提交
23 24
* **git 1.7.3** or newer
* **Ruby 1.8.6** or newer
C
tweak  
Chris Wanstrath 已提交
25

M
Mislav Marohnić 已提交
26
### Homebrew
C
tweaks  
Chris Wanstrath 已提交
27

M
Mislav Marohnić 已提交
28
Installing on OS X is easiest with Homebrew:
C
readme  
Chris Wanstrath 已提交
29

M
Mislav Marohnić 已提交
30 31 32
~~~ sh
$ brew install hub
~~~
C
readme  
Chris Wanstrath 已提交
33

34
### `rake install` from source
C
Chris Wanstrath 已提交
35

36 37
This is the preferred installation method without when no package manager that
supports hub is available:
C
Chris Wanstrath 已提交
38

M
Mislav Marohnić 已提交
39
~~~ sh
40 41 42 43
# Download or clone the project from GitHub:
$ git clone git://github.com/github/hub.git
$ cd hub
$ rake install
M
Mislav Marohnić 已提交
44
~~~
C
Chris Wanstrath 已提交
45

46 47 48
On a Unix-based OS, this installs under `PREFIX`, which is `/usr/local` by default.

Now you should be ready to roll:
C
Chris Wanstrath 已提交
49

M
Mislav Marohnić 已提交
50 51 52 53 54
~~~ sh
$ hub version
git version 1.7.6
hub version 1.8.3
~~~
55

T
Timothy Gu 已提交
56
#### Windows "Git Bash" (msysGit) note
57

T
Timothy Gu 已提交
58
Avoid aliasing hub as `git` due to the fact that msysGit automatically
59 60 61
configures your prompt to include git information, and you want to avoid slowing
that down. See [Is your shell prompt slow?](#is-your-shell-prompt-slow)

62
### RubyGems
C
Chris Wanstrath 已提交
63

M
Mislav Marohnić 已提交
64
Though not recommended, hub can also be installed as a RubyGem:
C
Chris Wanstrath 已提交
65

M
Mislav Marohnić 已提交
66 67 68
~~~ sh
$ gem install hub
~~~
C
Chris Wanstrath 已提交
69

70 71
(It's not recommended for casual use because of the RubyGems startup
time. See [this gist][speed] for information.)
72

M
Mislav Marohnić 已提交
73
#### Standalone via RubyGems
74

M
Mislav Marohnić 已提交
75 76 77 78
~~~ sh
$ gem install hub
$ hub hub standalone > ~/bin/hub && chmod +x ~/bin/hub
~~~
79 80

This installs a standalone version which doesn't require RubyGems to
M
Mislav Marohnić 已提交
81
run, so it's faster.
82

83
### Help! It's slow!
C
Chris Wanstrath 已提交
84

85
#### Is `hub` noticeably slower than plain git?
C
Chris Wanstrath 已提交
86

87 88
That is inconvenient, especially if you want to alias hub as `git`. Few things
you can try:
C
Chris Wanstrath 已提交
89

90
* Find out which ruby is used for the hub executable:
C
Chris Wanstrath 已提交
91

92 93 94
    ``` sh
    head -1 `which hub`
    ```
C
Chris Wanstrath 已提交
95

96
* That ruby should be speedy. Time it with:
C
Chris Wanstrath 已提交
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    ``` sh
    time /usr/bin/ruby -e0
    #=> it should be below 0.01 s total
    ```

* Check that Ruby isn't loading something shady:

    ``` sh
    echo $RUBYOPT
    ```

* Check your [GC settings][gc]

General recommendation: you should change hub's shebang line to run with system
ruby (usually `/usr/bin/ruby`) instead of currently active ruby (`/usr/bin/env
ruby`). Also, Ruby 1.8 is speedier than 1.9.

#### Is your shell prompt slow?

Does your prompt show git information? Hub may be slowing down your prompt.

This can happen if you've aliased hub as `git`. This is fine when you use `git`
manually, but may be unacceptable for your prompt, which doesn't need hub
features anyway!

The solution is to identify which shell functions are calling `git`, and replace
each occurrence of that with `command git`. This is a shell feature that enables
you to call a command directly and skip aliases and functions wrapping it.
C
Chris Wanstrath 已提交
126

C
readme  
Chris Wanstrath 已提交
127

C
Chris Wanstrath 已提交
128 129
Aliasing
--------
C
readme  
Chris Wanstrath 已提交
130

M
Mislav Marohnić 已提交
131 132
Using hub feels best when it's aliased as `git`. This is not dangerous; your
_normal git commands will all work_. hub merely adds some sugar.
C
readme  
Chris Wanstrath 已提交
133

134 135
`hub alias` displays instructions for the current shell. With the `-s` flag, it
outputs a script suitable for `eval`.
C
Chris Wanstrath 已提交
136

137
You should place this command in your `.bash_profile` or other startup script:
C
Chris Wanstrath 已提交
138

M
Mislav Marohnić 已提交
139
~~~ sh
140
eval "$(hub alias -s)"
M
Mislav Marohnić 已提交
141
~~~
C
tweaks  
Chris Wanstrath 已提交
142

143 144 145 146 147
### Shell tab-completion

hub repository contains tab-completion scripts for bash and zsh. These scripts
complement existing completion scripts that ship with git.

M
Mislav Marohnić 已提交
148 149
* [hub bash completion](https://github.com/github/hub/blob/master/etc/hub.bash_completion.sh)
* [hub zsh completion](https://github.com/github/hub/blob/master/etc/hub.zsh_completion)
150

C
readme  
Chris Wanstrath 已提交
151

C
Chris Wanstrath 已提交
152
Commands
C
readme  
Chris Wanstrath 已提交
153 154
--------

M
Mislav Marohnić 已提交
155
Assuming you've aliased hub as `git`, the following commands now have
C
Chris Wanstrath 已提交
156 157
superpowers:

C
readme  
Chris Wanstrath 已提交
158 159 160
### git clone

    $ git clone schacon/ticgit
C
Chris Wanstrath 已提交
161 162
    > git clone git://github.com/schacon/ticgit.git

C
readme  
Chris Wanstrath 已提交
163
    $ git clone -p schacon/ticgit
C
Chris Wanstrath 已提交
164
    > git clone git@github.com:schacon/ticgit.git
C
readme  
Chris Wanstrath 已提交
165

166
    $ git clone resque
167
    > git clone git@github.com/YOUR_USER/resque.git
168

C
readme  
Chris Wanstrath 已提交
169 170 171
### git remote add

    $ git remote add rtomayko
C
Chris Wanstrath 已提交
172 173
    > git remote add rtomayko git://github.com/rtomayko/CURRENT_REPO.git

K
Konstantin Haase 已提交
174
    $ git remote add -p rtomayko
C
Chris Wanstrath 已提交
175
    > git remote add rtomayko git@github.com:rtomayko/CURRENT_REPO.git
C
readme  
Chris Wanstrath 已提交
176

177 178 179
    $ git remote add origin
    > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

180 181 182 183 184 185 186 187 188 189 190
### 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

191 192 193 194 195 196 197 198 199 200 201 202 203 204
### 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 cherry-pick mislav@SHA
    > git remote add -f mislav git://github.com/mislav/CURRENT_REPO.git
    > git cherry-pick SHA

    $ git cherry-pick mislav@SHA
    > git fetch mislav
    > git cherry-pick SHA

205
### git am, git apply
206 207 208 209 210 211 212 213 214

    $ 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 am --ignore-whitespace https://github.com/davidbalbert/hub/commit/fdb9921
    > curl https://github.com/davidbalbert/hub/commit/fdb9921.patch -o /tmp/fdb9921.patch
    > git am --ignore-whitespace /tmp/fdb9921.patch

215 216 217 218
    $ git apply https://gist.github.com/8da7fb575debd88c54cf
    > curl https://gist.github.com/8da7fb575debd88c54cf.txt -o /tmp/gist-8da7fb575debd88c54cf.txt
    > git apply /tmp/gist-8da7fb575debd88c54cf.txt

219 220 221
### git fork

    $ git fork
222
    [ repo forked on GitHub ]
C
Chris Wanstrath 已提交
223
    > git remote add -f YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
224

225 226
### git pull-request

227
    # while on a topic branch called "feature":
228 229
    $ git pull-request
    [ opens text editor to edit title & body for the request ]
230
    [ opened pull request on GitHub for "YOUR_USER:feature" ]
231

232
    # explicit title, pull base & head:
233
    $ git pull-request -m "Implemented feature X" -b defunkt:master -h mislav:feature
234

M
Mislav Marohnić 已提交
235
    $ git pull-request -i 123
236
    [ attached pull request to issue #123 ]
237

238 239
### git checkout

240 241 242
    $ git checkout https://github.com/defunkt/hub/pull/73
    > git remote add -f -t feature git://github:com/mislav/hub.git
    > git checkout --track -B mislav-feature mislav/feature
243

244 245 246 247 248 249 250
    $ git checkout https://github.com/defunkt/hub/pull/73 custom-branch-name

### git merge

    $ git merge https://github.com/defunkt/hub/pull/73
    > git fetch git://github.com/mislav/hub.git +refs/heads/feature:refs/remotes/mislav/feature
    > git merge mislav/feature --no-ff -m 'Merge pull request #73 from mislav/feature...'
251

252 253 254
### git create

    $ git create
255
    [ repo created on GitHub ]
256 257
    > git remote add origin git@github.com:YOUR_USER/CURRENT_REPO.git

258 259 260 261 262 263 264 265 266 267 268
    # with description:
    $ git create -d 'It shall be mine, all mine!'

    $ git create recipes
    [ repo created on GitHub ]
    > git remote add origin git@github.com:YOUR_USER/recipes.git

    $ git create sinatra/recipes
    [ repo created in GitHub organization ]
    > git remote add origin git@github.com:sinatra/recipes.git

C
readme  
Chris Wanstrath 已提交
269 270
### git init

C
Chris Wanstrath 已提交
271
    $ git init -g
C
Chris Wanstrath 已提交
272
    > git init
273
    > git remote add origin git@github.com:YOUR_USER/REPO.git
C
Chris Wanstrath 已提交
274

275 276 277 278 279 280 281
### git push

    $ git push origin,staging,qa bert_timeout
    > git push origin bert_timeout
    > git push staging bert_timeout
    > git push qa bert_timeout

282 283
### git browse

284
    $ git browse
J
Justin Quick 已提交
285
    > open https://github.com/YOUR_USER/CURRENT_REPO
286

287 288 289
    $ git browse -- commit/SHA
    > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

290
    $ git browse -- issues
J
Justin Quick 已提交
291
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues
292

293
    $ git browse schacon/ticgit
294
    > open https://github.com/schacon/ticgit
295

296 297 298
    $ git browse schacon/ticgit commit/SHA
    > open https://github.com/schacon/ticgit/commit/SHA

299
    $ git browse resque
300
    > open https://github.com/YOUR_USER/resque
301

302
    $ git browse resque network
303
    > open https://github.com/YOUR_USER/resque/network
304

J
Joshua Roesslein 已提交
305 306 307
### git compare

    $ git compare refactor
308
    > open https://github.com/CURRENT_REPO/compare/refactor
J
Joshua Roesslein 已提交
309

310
    $ git compare 1.0..1.1
311
    > open https://github.com/CURRENT_REPO/compare/1.0...1.1
J
Joshua Roesslein 已提交
312 313

    $ git compare -u fix
314
    > (https://github.com/CURRENT_REPO/compare/fix)
J
Joshua Roesslein 已提交
315

316
    $ git compare other-user patch
317
    > open https://github.com/other-user/REPO/compare/patch
J
Joshua Roesslein 已提交
318

J
Justin Ridgewell 已提交
319
### git submodule
320

J
Justin Ridgewell 已提交
321 322 323 324 325 326
    $ hub submodule add wycats/bundler vendor/bundler
    > git submodule add git://github.com/wycats/bundler.git vendor/bundler

    $ hub submodule add -p wycats/bundler vendor/bundler
    > git submodule add git@github.com:wycats/bundler.git vendor/bundler

327 328
    $ hub submodule add -b ryppl --name pip ryppl/pip vendor/pip
    > git submodule add -b ryppl --name pip git://github.com/ryppl/pip.git vendor/pip
J
Justin Ridgewell 已提交
329

330 331
### git ci-status

M
Mislav Marohnić 已提交
332 333
    $ hub ci-status [commit]
    > (prints CI state of commit and exits with appropriate code)
334 335
    > One of: success (0), error (1), failure (1), pending (2), no status (3)

J
Justin Ridgewell 已提交
336

C
Chris Wanstrath 已提交
337 338 339 340
### git help

    $ git help
    > (improved git help)
C
Chris Wanstrath 已提交
341 342
    $ git help hub
    > (hub man page)
C
readme  
Chris Wanstrath 已提交
343 344


M
Mislav Marohnić 已提交
345 346 347
Configuration
-------------

348
### GitHub OAuth authentication
C
Chris Wanstrath 已提交
349

350 351
Hub will prompt for GitHub username & password the first time it needs to access
the API and exchange it for an OAuth token, which it saves in "~/.config/hub".
C
Chris Wanstrath 已提交
352

B
Bruno Binet 已提交
353
### HTTPS instead of git protocol
C
Chris Wanstrath 已提交
354

355 356
If you prefer using the HTTPS protocol for GitHub repositories instead of the git
protocol for read and ssh for write, you can set "hub.protocol" to "https".
C
Chris Wanstrath 已提交
357

M
Mislav Marohnić 已提交
358 359 360 361
~~~ sh
# default behavior
$ git clone defunkt/repl
< git clone >
C
Chris Wanstrath 已提交
362

M
Mislav Marohnić 已提交
363 364 365 366 367
# opt into HTTPS:
$ git config --global hub.protocol https
$ git clone defunkt/repl
< https clone >
~~~
C
readme  
Chris Wanstrath 已提交
368 369


C
Chris Wanstrath 已提交
370 371 372
Contributing
------------

373
These instructions assume that _you already have hub installed_ and aliased as
M
Mislav Marohnić 已提交
374
`git` (see "Aliasing").
M
Mislav Marohnić 已提交
375 376

1. Clone hub:  
M
Mislav Marohnić 已提交
377
    `git clone github/hub && cd hub`
378 379
1. Ensure Bundler is installed:  
    `which bundle || gem install bundler`
M
Mislav Marohnić 已提交
380 381 382 383
1. Install development dependencies:  
    `bundle install`
2. Verify that existing tests pass:  
    `bundle exec rake`
M
Mislav Marohnić 已提交
384
3. Create a topic branch:  
M
Mislav Marohnić 已提交
385 386
    `git checkout -b feature`
4. **Make your changes.** (It helps a lot if you write tests first.)
M
Mislav Marohnić 已提交
387
5. Verify that tests still pass:  
M
Mislav Marohnić 已提交
388
    `bundle exec rake`
M
Mislav Marohnić 已提交
389 390 391
6. Fork hub on GitHub (adds a remote named "YOUR_USER"):  
    `git fork`
7. Push to your fork:  
M
Mislav Marohnić 已提交
392
    `git push -u YOUR_USER feature`
M
Mislav Marohnić 已提交
393 394 395
8. Open a pull request describing your changes:  
    `git pull-request`

C
Chris Wanstrath 已提交
396

C
Chris Wanstrath 已提交
397 398
Meta
----
C
readme  
Chris Wanstrath 已提交
399

M
Mislav Marohnić 已提交
400 401
* Home: <https://github.com/github/hub>
* Bugs: <https://github.com/github/hub/issues>
M
Mislav Marohnić 已提交
402
* Gem: <https://rubygems.org/gems/hub>
M
Mislav Marohnić 已提交
403
* Authors: <https://github.com/github/hub/contributors>
M
Mislav Marohnić 已提交
404 405

### Prior art
C
Chris Wanstrath 已提交
406

M
Mislav Marohnić 已提交
407 408
These projects also aim to either improve git or make interacting with
GitHub simpler:
C
Chris Wanstrath 已提交
409

M
Mislav Marohnić 已提交
410 411
* [eg](http://www.gnome.org/~newren/eg/)
* [github-gem](https://github.com/defunkt/github-gem)
C
Chris Wanstrath 已提交
412 413


414
[speed]: http://gist.github.com/284823
C
Chris Wanstrath 已提交
415
[gc]: https://twitter.com/brynary/status/49560668994674688