README.md 9.6 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

C
Chris Wanstrath 已提交
34 35
### Standalone

M
Mislav Marohnić 已提交
36
`hub` is easily installed as a standalone script:
C
Chris Wanstrath 已提交
37

M
Mislav Marohnić 已提交
38 39 40 41
~~~ sh
$ curl http://defunkt.io/hub/standalone -sLo ~/bin/hub &&
  chmod +x ~/bin/hub
~~~
C
Chris Wanstrath 已提交
42

M
Mislav Marohnić 已提交
43
Assuming "~/bin/" is in your `$PATH`, you're ready to roll:
C
Chris Wanstrath 已提交
44

M
Mislav Marohnić 已提交
45 46 47 48 49
~~~ sh
$ hub version
git version 1.7.6
hub version 1.8.3
~~~
50

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

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

M
Mislav Marohnić 已提交
55 56 57
~~~ sh
$ gem install hub
~~~
C
Chris Wanstrath 已提交
58

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

M
Mislav Marohnić 已提交
62
#### Standalone via RubyGems
63

M
Mislav Marohnić 已提交
64 65 66 67
~~~ sh
$ gem install hub
$ hub hub standalone > ~/bin/hub && chmod +x ~/bin/hub
~~~
68 69

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

C
Chris Wanstrath 已提交
72 73
### Source

C
Chris Wanstrath 已提交
74
You can also install from source:
C
readme  
Chris Wanstrath 已提交
75

M
Mislav Marohnić 已提交
76 77 78 79
~~~ sh
$ git clone git://github.com/defunkt/hub.git
$ cd hub && rake install prefix=/usr/local
~~~
C
readme  
Chris Wanstrath 已提交
80

C
Chris Wanstrath 已提交
81 82 83 84 85 86 87
### 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:

M
Mislav Marohnić 已提交
88
        $ echo $RUBYOPT
C
Chris Wanstrath 已提交
89 90 91

3. Check that your system Ruby is speedy:

M
Mislav Marohnić 已提交
92
        $ time /usr/bin/env ruby -e0
C
Chris Wanstrath 已提交
93 94 95

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

C
readme  
Chris Wanstrath 已提交
96

C
Chris Wanstrath 已提交
97 98
Aliasing
--------
C
readme  
Chris Wanstrath 已提交
99

M
Mislav Marohnić 已提交
100 101
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 已提交
102

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

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

M
Mislav Marohnić 已提交
108
~~~ sh
109
eval "$(hub alias -s)"
M
Mislav Marohnić 已提交
110
~~~
C
tweaks  
Chris Wanstrath 已提交
111

112 113 114 115 116 117 118 119
### Shell tab-completion

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

* [hub bash completion](https://github.com/defunkt/hub/blob/master/etc/hub.bash_completion.sh)
* [hub zsh completion](https://github.com/defunkt/hub/blob/master/etc/hub.zsh_completion)

C
readme  
Chris Wanstrath 已提交
120

C
Chris Wanstrath 已提交
121
Commands
C
readme  
Chris Wanstrath 已提交
122 123
--------

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

C
readme  
Chris Wanstrath 已提交
127 128 129
### git clone

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

C
readme  
Chris Wanstrath 已提交
132
    $ git clone -p schacon/ticgit
C
Chris Wanstrath 已提交
133
    > git clone git@github.com:schacon/ticgit.git
C
readme  
Chris Wanstrath 已提交
134

135
    $ git clone resque
136
    > git clone git@github.com/YOUR_USER/resque.git
137

C
readme  
Chris Wanstrath 已提交
138 139 140
### git remote add

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

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

146 147 148
    $ git remote add origin
    > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

149 150 151 152 153 154 155 156 157 158 159
### 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

160 161 162 163 164 165 166 167 168 169 170 171 172 173
### 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

174
### git am, git apply
175 176 177 178 179 180 181 182 183

    $ 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

184 185 186 187
    $ 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

188 189 190
### git fork

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

194 195
### git pull-request

196
    # while on a topic branch called "feature":
197 198
    $ git pull-request
    [ opens text editor to edit title & body for the request ]
199
    [ opened pull request on GitHub for "YOUR_USER:feature" ]
200

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

M
Mislav Marohnić 已提交
204
    $ git pull-request -i 123
205
    [ attached pull request to issue #123 ]
206

207 208 209 210
### git checkout

    # $ git checkout https://github.com/defunkt/hub/pull/73
    # > git remote add -f -t feature git://github:com/mislav/hub.git
M
Mislav Marohnić 已提交
211
    # > git checkout --track -B mislav-feature mislav/feature
212 213 214

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

215 216 217
### git create

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

221 222 223 224 225 226 227 228 229 230 231
    # 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 已提交
232 233
### git init

C
Chris Wanstrath 已提交
234
    $ git init -g
C
Chris Wanstrath 已提交
235
    > git init
236
    > git remote add origin git@github.com:YOUR_USER/REPO.git
C
Chris Wanstrath 已提交
237

238 239 240 241 242 243 244
### git push

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

245 246
### git browse

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

250 251 252
    $ git browse -- commit/SHA
    > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

253
    $ git browse -- issues
J
Justin Quick 已提交
254
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues
255

256
    $ git browse schacon/ticgit
257
    > open https://github.com/schacon/ticgit
258

259 260 261
    $ git browse schacon/ticgit commit/SHA
    > open https://github.com/schacon/ticgit/commit/SHA

262
    $ git browse resque
263
    > open https://github.com/YOUR_USER/resque
264

265
    $ git browse resque network
266
    > open https://github.com/YOUR_USER/resque/network
267

J
Joshua Roesslein 已提交
268 269 270
### git compare

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

273
    $ git compare 1.0..1.1
274
    > open https://github.com/CURRENT_REPO/compare/1.0...1.1
J
Joshua Roesslein 已提交
275 276

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

279
    $ git compare other-user patch
280
    > open https://github.com/other-user/REPO/compare/patch
J
Joshua Roesslein 已提交
281

J
Justin Ridgewell 已提交
282
### git submodule
283

J
Justin Ridgewell 已提交
284 285 286 287 288 289
    $ 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

290
    $ hub submodule add -b ryppl ryppl/pip vendor/pip
J
Justin Ridgewell 已提交
291 292 293
    > git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip


C
Chris Wanstrath 已提交
294 295 296 297
### git help

    $ git help
    > (improved git help)
C
Chris Wanstrath 已提交
298 299
    $ git help hub
    > (hub man page)
C
readme  
Chris Wanstrath 已提交
300 301


M
Mislav Marohnić 已提交
302 303 304 305
Configuration
-------------

### GitHub username & token
C
Chris Wanstrath 已提交
306

M
Mislav Marohnić 已提交
307
To get the most out of hub, you'll want to ensure your GitHub login
308
is stored locally in your Git config or environment variables.
C
Chris Wanstrath 已提交
309 310 311 312 313 314 315

To test it run this:

    $ git config --global github.user

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

C
Chris Wanstrath 已提交
316
    $ git config --global github.user YOUR_USER
C
Chris Wanstrath 已提交
317

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

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

M
Mislav Marohnić 已提交
324
### HTTPS insted of git protocol
C
Chris Wanstrath 已提交
325

326 327
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 已提交
328

M
Mislav Marohnić 已提交
329 330 331 332
~~~ sh
# default behavior
$ git clone defunkt/repl
< git clone >
C
Chris Wanstrath 已提交
333

M
Mislav Marohnić 已提交
334 335 336 337 338
# opt into HTTPS:
$ git config --global hub.protocol https
$ git clone defunkt/repl
< https clone >
~~~
C
readme  
Chris Wanstrath 已提交
339 340


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

M
Mislav Marohnić 已提交
344 345
These instructions assume that you already have hub installed and aliased as
`git` (see "Aliasing").
M
Mislav Marohnić 已提交
346 347

1. Clone hub:  
M
Mislav Marohnić 已提交
348 349 350 351 352
    `git clone defunkt/hub && cd hub`
1. Install development dependencies:  
    `bundle install`
2. Verify that existing tests pass:  
    `bundle exec rake`
M
Mislav Marohnić 已提交
353
3. Create a topic branch:  
M
Mislav Marohnić 已提交
354 355
    `git checkout -b feature`
4. **Make your changes.** (It helps a lot if you write tests first.)
M
Mislav Marohnić 已提交
356
5. Verify that tests still pass:  
M
Mislav Marohnić 已提交
357
    `bundle exec rake`
M
Mislav Marohnić 已提交
358 359 360
6. Fork hub on GitHub (adds a remote named "YOUR_USER"):  
    `git fork`
7. Push to your fork:  
M
Mislav Marohnić 已提交
361
    `git push -u YOUR_USER feature`
M
Mislav Marohnić 已提交
362 363 364
8. Open a pull request describing your changes:  
    `git pull-request`

C
Chris Wanstrath 已提交
365

C
Chris Wanstrath 已提交
366 367
Meta
----
C
readme  
Chris Wanstrath 已提交
368

M
Mislav Marohnić 已提交
369 370 371
* Home: <https://github.com/defunkt/hub>
* Bugs: <https://github.com/defunkt/hub/issues>
* Gem: <https://rubygems.org/gems/hub>
M
Mislav Marohnić 已提交
372 373 374
* Authors: <https://github.com/defunkt/hub/contributors>

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

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

M
Mislav Marohnić 已提交
379 380
* [eg](http://www.gnome.org/~newren/eg/)
* [github-gem](https://github.com/defunkt/github-gem)
C
Chris Wanstrath 已提交
381 382


383
[speed]: http://gist.github.com/284823
384
[2]: http://help.github.com/set-your-user-name-email-and-github-token/
C
Chris Wanstrath 已提交
385
[gc]: https://twitter.com/brynary/status/49560668994674688