README.md 9.2 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
* **git 1.7.3** or newer
C
tweak  
Chris Wanstrath 已提交
24

O
Owen Ou 已提交
25 26 27 28 29
### 2.x

Starting from 2.2.0, `hub` is [powered by Go](https://github.com/github/hub/issues/475).
It should maintain a high backward compatibility with 1.x. Note that 2.x is in preview.

30 31 32 33 34 35 36 37 38
#### Homebrew

`hub` 2.x can be installed through Homebrew. Since it's in preview, you need to compile
from HEAD:

~~~ sh
$ brew install --HEAD hub
~~~

O
Owen Ou 已提交
39 40 41
#### Standalone

`hub` 2.x can be easily installed as an executable. Download the latest
42 43
[compiled binaries](https://github.com/github/hub/releases) and put it anywhere
in your executable path.
O
Owen Ou 已提交
44 45 46 47

#### Source

To install `hub` 2.x from source, you need to have a [Go development environment](http://golang.org/doc/install),
J
Jingwen Owen Ou 已提交
48
version 1.4 or better:
O
Owen Ou 已提交
49 50 51 52 53 54 55 56 57 58 59

~~~ sh
$ git clone https://github.com/github/hub.git
$ cd hub
$ ./script/build
$ cp hub YOUR_BIN_PATH
~~~

### 1.x

#### Homebrew
C
tweaks  
Chris Wanstrath 已提交
60

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

M
Mislav Marohnić 已提交
63 64 65
~~~ sh
$ brew install hub
~~~
C
readme  
Chris Wanstrath 已提交
66

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

M
Mislav Marohnić 已提交
69 70 71 72 73
~~~ sh
$ hub version
git version 1.7.6
hub version 1.8.3
~~~
74

C
readme  
Chris Wanstrath 已提交
75

C
Chris Wanstrath 已提交
76 77
Aliasing
--------
C
readme  
Chris Wanstrath 已提交
78

M
Mislav Marohnić 已提交
79 80
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 已提交
81

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

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

M
Mislav Marohnić 已提交
87
~~~ sh
88
eval "$(hub alias -s)"
M
Mislav Marohnić 已提交
89
~~~
C
tweaks  
Chris Wanstrath 已提交
90

91 92 93 94 95
### 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ć 已提交
96 97
* [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)
98

C
readme  
Chris Wanstrath 已提交
99

C
Chris Wanstrath 已提交
100
Commands
C
readme  
Chris Wanstrath 已提交
101 102
--------

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

C
readme  
Chris Wanstrath 已提交
106 107 108
### git clone

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

C
readme  
Chris Wanstrath 已提交
111
    $ git clone -p schacon/ticgit
C
Chris Wanstrath 已提交
112
    > git clone git@github.com:schacon/ticgit.git
C
readme  
Chris Wanstrath 已提交
113

114
    $ git clone resque
115
    > git clone git@github.com/YOUR_USER/resque.git
116

C
readme  
Chris Wanstrath 已提交
117 118 119
### git remote add

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

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

125 126 127
    $ git remote add origin
    > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

128 129 130 131 132 133 134 135 136 137 138
### 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

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

153
### git am, git apply
154 155

    $ git am https://github.com/defunkt/hub/pull/55
156
    [ downloads patch via API ]
157 158 159
    > git am /tmp/55.patch

    $ git am --ignore-whitespace https://github.com/davidbalbert/hub/commit/fdb9921
160
    [ downloads patch via API ]
161 162
    > git am --ignore-whitespace /tmp/fdb9921.patch

163
    $ git apply https://gist.github.com/8da7fb575debd88c54cf
164
    [ downloads patch via API ]
165 166
    > git apply /tmp/gist-8da7fb575debd88c54cf.txt

167 168 169
### git fork

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

173 174
### git pull-request

175
    # while on a topic branch called "feature":
176 177
    $ git pull-request
    [ opens text editor to edit title & body for the request ]
178
    [ opened pull request on GitHub for "YOUR_USER:feature" ]
179

180
    # explicit title, pull base & head:
181
    $ git pull-request -m "Implemented feature X" -b defunkt:master -h mislav:feature
182

183 184
### git checkout

185
    $ git checkout https://github.com/defunkt/hub/pull/73
186
    > git remote add -f -t feature mislav git://github.com/mislav/hub.git
187
    > git checkout --track -B mislav-feature mislav/feature
188

189 190 191 192 193 194 195
    $ 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...'
196

197 198 199
### git create

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

203 204 205 206 207 208 209 210 211 212 213
    # 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 已提交
214 215
### git init

C
Chris Wanstrath 已提交
216
    $ git init -g
C
Chris Wanstrath 已提交
217
    > git init
218
    > git remote add origin git@github.com:YOUR_USER/REPO.git
C
Chris Wanstrath 已提交
219

220 221 222 223 224 225 226
### git push

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

227 228
### git browse

229
    $ git browse
J
Justin Quick 已提交
230
    > open https://github.com/YOUR_USER/CURRENT_REPO
231

232 233 234
    $ git browse -- commit/SHA
    > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

235
    $ git browse -- issues
J
Justin Quick 已提交
236
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues
237

R
Richard Littauer 已提交
238 239 240
    $ git browse -- issues/10
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues/10

241
    $ git browse schacon/ticgit
242
    > open https://github.com/schacon/ticgit
243

244 245 246
    $ git browse schacon/ticgit commit/SHA
    > open https://github.com/schacon/ticgit/commit/SHA

247
    $ git browse resque
248
    > open https://github.com/YOUR_USER/resque
249

250
    $ git browse resque network
251
    > open https://github.com/YOUR_USER/resque/network
252

J
Joshua Roesslein 已提交
253 254 255
### git compare

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

258
    $ git compare 1.0..1.1
259
    > open https://github.com/CURRENT_REPO/compare/1.0...1.1
J
Joshua Roesslein 已提交
260 261

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

264
    $ git compare other-user patch
265
    > open https://github.com/other-user/REPO/compare/patch
J
Joshua Roesslein 已提交
266

J
Justin Ridgewell 已提交
267
### git submodule
268

269
    $ git submodule add wycats/bundler vendor/bundler
J
Justin Ridgewell 已提交
270 271
    > git submodule add git://github.com/wycats/bundler.git vendor/bundler

272
    $ git submodule add -p wycats/bundler vendor/bundler
J
Justin Ridgewell 已提交
273 274
    > git submodule add git@github.com:wycats/bundler.git vendor/bundler

275
    $ git submodule add -b ryppl --name pip ryppl/pip vendor/pip
276
    > git submodule add -b ryppl --name pip git://github.com/ryppl/pip.git vendor/pip
J
Justin Ridgewell 已提交
277

278 279
### git ci-status

280
    $ git ci-status [commit]
M
Mislav Marohnić 已提交
281
    > (prints CI state of commit and exits with appropriate code)
282 283
    > One of: success (0), error (1), failure (1), pending (2), no status (3)

J
Justin Ridgewell 已提交
284

C
Chris Wanstrath 已提交
285 286 287 288
### git help

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


M
Mislav Marohnić 已提交
293 294 295
Configuration
-------------

296
### GitHub OAuth authentication
C
Chris Wanstrath 已提交
297

298 299
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 已提交
300

301 302 303
To avoid being prompted, use **GITHUB_USER** and **GITHUB_PASSWORD** environment
variables.

B
Bruno Binet 已提交
304
### HTTPS instead of git protocol
C
Chris Wanstrath 已提交
305

306 307 308 309
If you prefer the HTTPS protocol for GitHub repositories, you can set
"hub.protocol" to "https". This will affect `clone`, `fork`, `remote add`
and other operations that expand references to GitHub repositories as full
URLs that otherwise use git and ssh protocols.
310 311 312

"hub.protocol" only applies when the "OWNER/REPO" shorthand is used instead of
a full git URL.
C
Chris Wanstrath 已提交
313

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    # default behavior
    $ git clone defunkt/repl
    < git clone >

    # opt into HTTPS:
    $ git config --global hub.protocol https
    $ git clone defunkt/repl
    < https clone >

### GitHub Enterprise

By default, hub will only work with repositories that have remotes which
point to github.com. GitHub Enterprise hosts need to be whitelisted to
configure hub to treat such remotes same as github.com:

    $ git config --global --add hub.host my.git.org

The default host for commands like `init` and `clone` is still
332
github.com, but this can be affected with the `GITHUB_HOST` environment
333
variable:
C
readme  
Chris Wanstrath 已提交
334

335
    $ GITHUB_HOST=my.git.org git clone myproject
C
readme  
Chris Wanstrath 已提交
336

C
Chris Wanstrath 已提交
337 338
Meta
----
C
readme  
Chris Wanstrath 已提交
339

M
Mislav Marohnić 已提交
340 341 342
* Home: <https://github.com/github/hub>
* Bugs: <https://github.com/github/hub/issues>
* Authors: <https://github.com/github/hub/contributors>
M
Mislav Marohnić 已提交
343 344

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

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

349
* [hub in Ruby](https://github.com/github/hub/tree/1.12-stable) (previous implementation)
M
Mislav Marohnić 已提交
350 351
* [eg](http://www.gnome.org/~newren/eg/)
* [github-gem](https://github.com/defunkt/github-gem)