README.md 9.6 KB
Newer Older
C
Chris Wanstrath 已提交
1 2
hub: git + hub = github
=======================
C
readme  
Chris Wanstrath 已提交
3

C
Chris Wanstrath 已提交
4
`hub` is a command line utility which adds GitHub knowledge to `git`.
C
readme  
Chris Wanstrath 已提交
5

B
Beau Dacious 已提交
6
It can be used on its own or as a `git` wrapper.
C
readme  
Chris Wanstrath 已提交
7

C
Chris Wanstrath 已提交
8
Normal:
C
Chris Wanstrath 已提交
9 10

    $ hub clone rtomayko/tilt
C
tweak  
Chris Wanstrath 已提交
11

12 13
    Expands to:
    $ git clone git://github.com/rtomayko/tilt.git
C
Chris Wanstrath 已提交
14

C
Chris Wanstrath 已提交
15
Wrapping `git`:
C
Chris Wanstrath 已提交
16 17 18

    $ git clone rack/rack

C
tweak  
Chris Wanstrath 已提交
19 20 21
    Expands to:
    $ git clone git://github.com/rack/rack.git

22
hub requires you have `git` installed and in your `$PATH`. It also
C
Chris Wanstrath 已提交
23
requires Ruby 1.8.6+ or Ruby 1.9.1+. No other libraries necessary.
C
tweaks  
Chris Wanstrath 已提交
24

C
readme  
Chris Wanstrath 已提交
25

C
Chris Wanstrath 已提交
26
Install
C
readme  
Chris Wanstrath 已提交
27 28
-------

C
Chris Wanstrath 已提交
29 30
### Standalone

C
tweaks  
Chris Wanstrath 已提交
31
`hub` is most easily installed as a standalone script:
C
Chris Wanstrath 已提交
32

33
    curl http://defunkt.io/hub/standalone -sLo ~/bin/hub &&
C
Chris Wanstrath 已提交
34
    chmod 755 ~/bin/hub
C
Chris Wanstrath 已提交
35

36
Assuming `~/bin/` is in your `$PATH`, you're ready to roll:
C
Chris Wanstrath 已提交
37

C
Chris Wanstrath 已提交
38
    $ hub version
39 40
    git version 1.7.0.4
    hub version 1.1.0
C
Chris Wanstrath 已提交
41

42 43
### Homebrew

44 45 46 47 48
    $ brew install hub
    $ which hub
    /usr/local/bin/hub
    $ hub version
    ...
49

50
### RubyGems
C
Chris Wanstrath 已提交
51

52
Though not recommended, `hub` can also be installed as a RubyGem:
C
Chris Wanstrath 已提交
53

C
Chris Wanstrath 已提交
54
    $ gem install hub
C
Chris Wanstrath 已提交
55

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

59 60
### Standalone via RubyGems

C
Chris Wanstrath 已提交
61
    $ gem install hub
62
    $ hub hub standalone > ~/bin/hub && chmod 755 ~/bin/hub
63 64 65

This installs a standalone version which doesn't require RubyGems to
run.
66

C
Chris Wanstrath 已提交
67 68
### Source

C
Chris Wanstrath 已提交
69
You can also install from source:
C
readme  
Chris Wanstrath 已提交
70 71 72

    $ git clone git://github.com/defunkt/hub.git
    $ cd hub
73
    $ rake install prefix=/usr/local
C
readme  
Chris Wanstrath 已提交
74

C
Chris Wanstrath 已提交
75 76 77 78 79 80 81
### Help! It's Slow!

Is your prompt slow? It may be hub.

1. Check that it's **not** installed using RubyGems.
2. Check that RUBYOPT isn't loading anything shady:

C
Chris Wanstrath 已提交
82
       $ echo $RUBYOPT
C
Chris Wanstrath 已提交
83 84 85

3. Check that your system Ruby is speedy:

C
Chris Wanstrath 已提交
86
       $ time /usr/bin/env ruby -e0
C
Chris Wanstrath 已提交
87 88 89

If #3 is slow, it may be your [GC settings][gc].

C
readme  
Chris Wanstrath 已提交
90

C
Chris Wanstrath 已提交
91 92
Aliasing
--------
C
readme  
Chris Wanstrath 已提交
93

94
`hub` works best when it wraps `git`. This is not dangerous - your
C
Chris Wanstrath 已提交
95
normal git commands should all work. hub merely adds some sugar.
C
readme  
Chris Wanstrath 已提交
96

C
Chris Wanstrath 已提交
97 98
Typing `hub alias <shell>` will display alias instructions for
your shell. `hub alias` alone will show the known shells.
C
readme  
Chris Wanstrath 已提交
99

C
Chris Wanstrath 已提交
100 101 102 103 104 105 106
For example:

    $ hub alias bash
    Run this in your shell to start using `hub` as `git`:
      alias git=hub

You should place this command in your `.bash_profile` or other startup
C
Chris Wanstrath 已提交
107
script to ensure runs on login.
C
Chris Wanstrath 已提交
108 109 110 111

The alias command can also be eval'd directly using the `-s` flag:

    $ eval `hub alias -s bash`
C
tweaks  
Chris Wanstrath 已提交
112

C
readme  
Chris Wanstrath 已提交
113

C
Chris Wanstrath 已提交
114
Commands
C
readme  
Chris Wanstrath 已提交
115 116
--------

117
Assuming you've aliased `hub` to `git`, the following commands now have
C
Chris Wanstrath 已提交
118 119
superpowers:

C
readme  
Chris Wanstrath 已提交
120 121 122
### git clone

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

C
readme  
Chris Wanstrath 已提交
125
    $ git clone -p schacon/ticgit
C
Chris Wanstrath 已提交
126
    > git clone git@github.com:schacon/ticgit.git
C
readme  
Chris Wanstrath 已提交
127

128
    $ git clone resque
129
    > git clone git@github.com/YOUR_USER/resque.git
130

C
readme  
Chris Wanstrath 已提交
131 132 133
### git remote add

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

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

139 140 141
    $ git remote add origin
    > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

142 143 144 145 146 147 148 149 150 151 152
### 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

153 154 155 156 157 158 159 160 161 162 163 164 165 166
### 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

167
### git am, git apply
168 169 170 171 172 173 174 175 176

    $ 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

177 178 179 180
    $ 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

181 182 183
### git fork

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

187 188
### git pull-request

189
    # while on a topic branch called "feature":
190 191
    $ git pull-request
    [ opens text editor to edit title & body for the request ]
192
    [ opened pull request on GitHub for "YOUR_USER:feature" ]
193

194 195
    # explicit title, pull base & head:
    $ git pull-request "I've implemented feature X" -b defunkt:master -h mislav:feature
196

M
Mislav Marohnić 已提交
197
    $ git pull-request -i 123
198
    [ attached pull request to issue #123 ]
199

200 201 202 203 204 205 206 207
### git checkout

    # $ git checkout https://github.com/defunkt/hub/pull/73
    # > git remote add -f -t feature git://github:com/mislav/hub.git
    # > git checkout -b mislav-feature mislav/feature

    # $ git checkout https://github.com/defunkt/hub/pull/73 custom-branch-name

208 209 210
### git create

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

214 215 216 217 218 219 220 221 222 223 224
    # 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 已提交
225 226
### git init

C
Chris Wanstrath 已提交
227
    $ git init -g
C
Chris Wanstrath 已提交
228
    > git init
229
    > git remote add origin git@github.com:YOUR_USER/REPO.git
C
Chris Wanstrath 已提交
230

231 232 233 234 235 236 237
### git push

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

238 239
### git browse

240
    $ git browse
J
Justin Quick 已提交
241
    > open https://github.com/YOUR_USER/CURRENT_REPO
242

243 244 245
    $ git browse -- commit/SHA
    > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

246
    $ git browse -- issues
J
Justin Quick 已提交
247
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues
248

249
    $ git browse schacon/ticgit
250
    > open https://github.com/schacon/ticgit
251

252 253 254
    $ git browse schacon/ticgit commit/SHA
    > open https://github.com/schacon/ticgit/commit/SHA

255
    $ git browse resque
256
    > open https://github.com/YOUR_USER/resque
257

258
    $ git browse resque network
259
    > open https://github.com/YOUR_USER/resque/network
260

J
Joshua Roesslein 已提交
261 262 263
### git compare

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

266
    $ git compare 1.0..1.1
267
    > open https://github.com/CURRENT_REPO/compare/1.0...1.1
J
Joshua Roesslein 已提交
268 269

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

272
    $ git compare other-user patch
273
    > open https://github.com/other-user/REPO/compare/patch
J
Joshua Roesslein 已提交
274

J
Justin Ridgewell 已提交
275
### git submodule
276

J
Justin Ridgewell 已提交
277 278 279 280 281 282
    $ 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

283
    $ hub submodule add -b ryppl ryppl/pip vendor/pip
J
Justin Ridgewell 已提交
284 285 286
    > git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip


C
Chris Wanstrath 已提交
287 288 289 290
### git help

    $ git help
    > (improved git help)
C
Chris Wanstrath 已提交
291 292
    $ git help hub
    > (hub man page)
C
readme  
Chris Wanstrath 已提交
293 294


C
Chris Wanstrath 已提交
295 296 297 298
GitHub Login
------------

To get the most out of `hub`, you'll want to ensure your GitHub login
299
is stored locally in your Git config or environment variables.
C
Chris Wanstrath 已提交
300 301 302 303 304 305 306

To test it run this:

    $ git config --global github.user

If you see nothing, you need to set the config setting:

C
Chris Wanstrath 已提交
307
    $ git config --global github.user YOUR_USER
C
Chris Wanstrath 已提交
308

309 310
For commands that require write access to GitHub (such as `fork`), you'll want to
setup "github.token" as well. See [local GitHub config guide][2] for more information.
C
Chris Wanstrath 已提交
311

312 313
If present, environment variables `GITHUB_USER` and `GITHUB_TOKEN` override the
values of "github.user" and "github.token".
C
Chris Wanstrath 已提交
314

C
Chris Wanstrath 已提交
315 316 317
Configuration
-------------

318 319
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 已提交
320 321 322 323 324

For example:

    $ git clone defunkt/repl
    < git clone >
325 326
    
    $ git config --global hub.protocol https
C
Chris Wanstrath 已提交
327
    $ git clone defunkt/repl
328
    < https clone >
C
Chris Wanstrath 已提交
329

C
Chris Wanstrath 已提交
330
Prior Art
C
readme  
Chris Wanstrath 已提交
331 332 333 334 335 336 337 338 339 340
---------

These projects also aim to either improve git or make interacting with
GitHub simpler:

* [eg](http://www.gnome.org/~newren/eg/)
* [github-gem](http://github.com/defunkt/github-gem)
* [gh](http://github.com/visionmedia/gh)


C
Chris Wanstrath 已提交
341 342 343
Contributing
------------

M
Mislav Marohnić 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
These instructions assume that you already have `hub` installed and that
you've set it up so it wraps `git` (see "Aliasing").

1. Clone hub:  
    `git clone defunkt/hub`
2. Verify that existing tests pass (see "Development dependencies"):  
    `rake test`
3. Create a topic branch:  
    `git checkout -b my_branch`
4. Make your changes – it helps a lot if you write tests first
5. Verify that tests still pass:  
    `rake test`
6. Fork hub on GitHub (adds a remote named "YOUR_USER"):  
    `git fork`
7. Push to your fork:  
    `git push -u YOUR_USER my_branch`
8. Open a pull request describing your changes:  
    `git pull-request`

### Development dependencies

You will need the following libraries for development:

* [ronn](https://github.com/rtomayko/ronn)
* [webmock](https://github.com/bblimke/webmock)
C
Chris Wanstrath 已提交
369

C
Chris Wanstrath 已提交
370 371
Meta
----
C
readme  
Chris Wanstrath 已提交
372

M
Mislav Marohnić 已提交
373 374 375
* Home: <https://github.com/defunkt/hub>
* Bugs: <https://github.com/defunkt/hub/issues>
* Gem: <https://rubygems.org/gems/hub>
C
Chris Wanstrath 已提交
376 377


C
Chris Wanstrath 已提交
378 379
Authors
-------
C
Chris Wanstrath 已提交
380

C
Chris Wanstrath 已提交
381
<https://github.com/defunkt/hub/contributors>
C
Chris Wanstrath 已提交
382

383
[speed]: http://gist.github.com/284823
384
[2]: http://github.com/guides/local-github-config
C
Chris Wanstrath 已提交
385
[gc]: https://twitter.com/brynary/status/49560668994674688