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

25 26
#### Homebrew

27
`hub` can be installed through Homebrew:
28 29

~~~ sh
30 31 32 33
$ brew install hub
$ hub version
git version 1.7.6
hub version 2.2.0
34 35
~~~

O
Owen Ou 已提交
36 37
#### Standalone

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

#### Source

44
To install `hub` from source, you need to have a [Go development environment](http://golang.org/doc/install),
J
Jingwen Owen Ou 已提交
45
version 1.4 or better:
O
Owen Ou 已提交
46 47 48 49 50 51 52 53

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

54 55 56 57 58 59 60
Or, if you've done Go development before and your $GOPATH/bin
directory is already in your PATH:

~~~ sh
$ go get github.com/github/hub
~~~

C
Chris Wanstrath 已提交
61 62
Aliasing
--------
C
readme  
Chris Wanstrath 已提交
63

M
Mislav Marohnić 已提交
64 65
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 已提交
66

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

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

M
Mislav Marohnić 已提交
72
~~~ sh
73
eval "$(hub alias -s)"
M
Mislav Marohnić 已提交
74
~~~
C
tweaks  
Chris Wanstrath 已提交
75

76 77 78 79 80
### Shell tab-completion

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

81 82
[Installation instructions](etc)

M
Mislav Marohnić 已提交
83 84
* [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)
85

C
Chris Wanstrath 已提交
86
Commands
C
readme  
Chris Wanstrath 已提交
87 88
--------

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

C
readme  
Chris Wanstrath 已提交
92 93 94
### git clone

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

C
readme  
Chris Wanstrath 已提交
97
    $ git clone -p schacon/ticgit
C
Chris Wanstrath 已提交
98
    > git clone git@github.com:schacon/ticgit.git
C
readme  
Chris Wanstrath 已提交
99

100
    $ git clone resque
101
    > git clone git@github.com/YOUR_USER/resque.git
102

C
readme  
Chris Wanstrath 已提交
103 104 105
### git remote add

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

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

111 112 113
    $ git remote add origin
    > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

114 115 116 117 118 119 120 121 122 123 124
### 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

125 126 127
### git cherry-pick

    $ git cherry-pick http://github.com/mislav/REPO/commit/SHA
128
    > git remote add -f --no-tags mislav git://github.com/mislav/REPO.git
129 130 131
    > git cherry-pick SHA

    $ git cherry-pick mislav@SHA
132
    > git remote add -f --no-tags mislav git://github.com/mislav/CURRENT_REPO.git
133 134 135 136 137 138
    > git cherry-pick SHA

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

139
### git am, git apply
140 141

    $ git am https://github.com/defunkt/hub/pull/55
142
    [ downloads patch via API ]
143 144 145
    > git am /tmp/55.patch

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

149
    $ git apply https://gist.github.com/8da7fb575debd88c54cf
150
    [ downloads patch via API ]
151 152
    > git apply /tmp/gist-8da7fb575debd88c54cf.txt

153 154 155
### git fork

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

159 160
### git pull-request

161
    # while on a topic branch called "feature":
162 163
    $ git pull-request
    [ opens text editor to edit title & body for the request ]
164
    [ opened pull request on GitHub for "YOUR_USER:feature" ]
165

166
    # explicit title, pull base & head:
167
    $ git pull-request -m "Implemented feature X" -b defunkt:master -h mislav:feature
168

169 170
### git checkout

171
    $ git checkout https://github.com/defunkt/hub/pull/73
172
    > git remote add -f --no-tags -t feature mislav git://github.com/mislav/hub.git
173
    > git checkout --track -B mislav-feature mislav/feature
174

175 176 177 178 179 180 181
    $ 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...'
182

183 184 185
### git create

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

189 190 191 192 193 194 195 196 197 198 199
    # 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 已提交
200 201
### git init

C
Chris Wanstrath 已提交
202
    $ git init -g
C
Chris Wanstrath 已提交
203
    > git init
204
    > git remote add origin git@github.com:YOUR_USER/REPO.git
C
Chris Wanstrath 已提交
205

206 207 208 209 210 211 212
### git push

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

213 214
### git browse

215
    $ git browse
J
Justin Quick 已提交
216
    > open https://github.com/YOUR_USER/CURRENT_REPO
217

218 219 220
    $ git browse -- commit/SHA
    > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

221
    $ git browse -- issues
J
Justin Quick 已提交
222
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues
223

R
Richard Littauer 已提交
224 225 226
    $ git browse -- issues/10
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues/10

227
    $ git browse schacon/ticgit
228
    > open https://github.com/schacon/ticgit
229

230 231 232
    $ git browse schacon/ticgit commit/SHA
    > open https://github.com/schacon/ticgit/commit/SHA

233
    $ git browse resque
234
    > open https://github.com/YOUR_USER/resque
235

236
    $ git browse resque network
237
    > open https://github.com/YOUR_USER/resque/network
238

J
Joshua Roesslein 已提交
239 240 241
### git compare

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

244
    $ git compare 1.0..1.1
245
    > open https://github.com/CURRENT_REPO/compare/1.0...1.1
J
Joshua Roesslein 已提交
246 247

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

250
    $ git compare other-user patch
251
    > open https://github.com/other-user/REPO/compare/patch
J
Joshua Roesslein 已提交
252

J
Justin Ridgewell 已提交
253
### git submodule
254

255
    $ git submodule add wycats/bundler vendor/bundler
J
Justin Ridgewell 已提交
256 257
    > git submodule add git://github.com/wycats/bundler.git vendor/bundler

258
    $ git submodule add -p wycats/bundler vendor/bundler
J
Justin Ridgewell 已提交
259 260
    > git submodule add git@github.com:wycats/bundler.git vendor/bundler

261
    $ git submodule add -b ryppl --name pip ryppl/pip vendor/pip
262
    > git submodule add -b ryppl --name pip git://github.com/ryppl/pip.git vendor/pip
J
Justin Ridgewell 已提交
263

264 265
### git ci-status

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

J
Justin Ridgewell 已提交
270

C
Chris Wanstrath 已提交
271 272 273 274
### git help

    $ git help
    > (improved git help)
C
Chris Wanstrath 已提交
275 276
    $ git help hub
    > (hub man page)
C
readme  
Chris Wanstrath 已提交
277 278


M
Mislav Marohnić 已提交
279 280 281
Configuration
-------------

282
### GitHub OAuth authentication
C
Chris Wanstrath 已提交
283

284 285
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 已提交
286

287 288 289
To avoid being prompted, use **GITHUB_USER** and **GITHUB_PASSWORD** environment
variables.

290 291 292
Alternatively, you may provide **GITHUB_TOKEN**, an access token with
**repo** permissions. This will not be written to `~/.config/hub`.

B
Bruno Binet 已提交
293
### HTTPS instead of git protocol
C
Chris Wanstrath 已提交
294

295 296 297 298
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.
299 300 301

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

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
    # 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
321
github.com, but this can be affected with the `GITHUB_HOST` environment
322
variable:
C
readme  
Chris Wanstrath 已提交
323

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

C
Chris Wanstrath 已提交
326 327
Meta
----
C
readme  
Chris Wanstrath 已提交
328

M
Mislav Marohnić 已提交
329 330 331
* Home: <https://github.com/github/hub>
* Bugs: <https://github.com/github/hub/issues>
* Authors: <https://github.com/github/hub/contributors>
M
Mislav Marohnić 已提交
332 333

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

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

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