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

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

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

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

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

M
Mislav Marohnić 已提交
35 36 37 38 39
~~~ sh
$ hub version
git version 1.7.6
hub version 1.8.3
~~~
40

C
readme  
Chris Wanstrath 已提交
41

C
Chris Wanstrath 已提交
42 43
Aliasing
--------
C
readme  
Chris Wanstrath 已提交
44

M
Mislav Marohnić 已提交
45 46
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 已提交
47

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

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

M
Mislav Marohnić 已提交
53
~~~ sh
54
eval "$(hub alias -s)"
M
Mislav Marohnić 已提交
55
~~~
C
tweaks  
Chris Wanstrath 已提交
56

57 58 59 60 61
### 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ć 已提交
62 63
* [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)
64

C
readme  
Chris Wanstrath 已提交
65

C
Chris Wanstrath 已提交
66
Commands
C
readme  
Chris Wanstrath 已提交
67 68
--------

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

C
readme  
Chris Wanstrath 已提交
72 73 74
### git clone

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

C
readme  
Chris Wanstrath 已提交
77
    $ git clone -p schacon/ticgit
C
Chris Wanstrath 已提交
78
    > git clone git@github.com:schacon/ticgit.git
C
readme  
Chris Wanstrath 已提交
79

80
    $ git clone resque
81
    > git clone git@github.com/YOUR_USER/resque.git
82

C
readme  
Chris Wanstrath 已提交
83 84 85
### git remote add

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

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

91 92 93
    $ git remote add origin
    > git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

94 95 96 97 98 99 100 101 102 103 104
### 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

105 106 107 108 109 110 111 112 113 114 115 116 117 118
### 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

119
### git am, git apply
120 121

    $ git am https://github.com/defunkt/hub/pull/55
122
    [ downloads patch via API ]
123 124 125
    > git am /tmp/55.patch

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

129
    $ git apply https://gist.github.com/8da7fb575debd88c54cf
130
    [ downloads patch via API ]
131 132
    > git apply /tmp/gist-8da7fb575debd88c54cf.txt

133 134 135
### git fork

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

139 140
### git pull-request

141
    # while on a topic branch called "feature":
142 143
    $ git pull-request
    [ opens text editor to edit title & body for the request ]
144
    [ opened pull request on GitHub for "YOUR_USER:feature" ]
145

146
    # explicit title, pull base & head:
147
    $ git pull-request -m "Implemented feature X" -b defunkt:master -h mislav:feature
148

149 150
### git checkout

151
    $ git checkout https://github.com/defunkt/hub/pull/73
152
    > git remote add -f -t feature mislav git://github.com/mislav/hub.git
153
    > git checkout --track -B mislav-feature mislav/feature
154

155 156 157 158 159 160 161
    $ 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...'
162

163 164 165
### git create

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

169 170 171 172 173 174 175 176 177 178 179
    # 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 已提交
180 181
### git init

C
Chris Wanstrath 已提交
182
    $ git init -g
C
Chris Wanstrath 已提交
183
    > git init
184
    > git remote add origin git@github.com:YOUR_USER/REPO.git
C
Chris Wanstrath 已提交
185

186 187 188 189 190 191 192
### git push

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

193 194
### git browse

195
    $ git browse
J
Justin Quick 已提交
196
    > open https://github.com/YOUR_USER/CURRENT_REPO
197

198 199 200
    $ git browse -- commit/SHA
    > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

201
    $ git browse -- issues
J
Justin Quick 已提交
202
    > open https://github.com/YOUR_USER/CURRENT_REPO/issues
203

204
    $ git browse schacon/ticgit
205
    > open https://github.com/schacon/ticgit
206

207 208 209
    $ git browse schacon/ticgit commit/SHA
    > open https://github.com/schacon/ticgit/commit/SHA

210
    $ git browse resque
211
    > open https://github.com/YOUR_USER/resque
212

213
    $ git browse resque network
214
    > open https://github.com/YOUR_USER/resque/network
215

J
Joshua Roesslein 已提交
216 217 218
### git compare

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

221
    $ git compare 1.0..1.1
222
    > open https://github.com/CURRENT_REPO/compare/1.0...1.1
J
Joshua Roesslein 已提交
223 224

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

227
    $ git compare other-user patch
228
    > open https://github.com/other-user/REPO/compare/patch
J
Joshua Roesslein 已提交
229

J
Justin Ridgewell 已提交
230
### git submodule
231

232
    $ git submodule add wycats/bundler vendor/bundler
J
Justin Ridgewell 已提交
233 234
    > git submodule add git://github.com/wycats/bundler.git vendor/bundler

235
    $ git submodule add -p wycats/bundler vendor/bundler
J
Justin Ridgewell 已提交
236 237
    > git submodule add git@github.com:wycats/bundler.git vendor/bundler

238
    $ git submodule add -b ryppl --name pip ryppl/pip vendor/pip
239
    > git submodule add -b ryppl --name pip git://github.com/ryppl/pip.git vendor/pip
J
Justin Ridgewell 已提交
240

241 242
### git ci-status

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

J
Justin Ridgewell 已提交
247

C
Chris Wanstrath 已提交
248 249 250 251
### git help

    $ git help
    > (improved git help)
C
Chris Wanstrath 已提交
252 253
    $ git help hub
    > (hub man page)
C
readme  
Chris Wanstrath 已提交
254 255


M
Mislav Marohnić 已提交
256 257 258
Configuration
-------------

259
### GitHub OAuth authentication
C
Chris Wanstrath 已提交
260

261 262
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 已提交
263

B
Bruno Binet 已提交
264
### HTTPS instead of git protocol
C
Chris Wanstrath 已提交
265

266 267
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 已提交
268

M
Mislav Marohnić 已提交
269 270 271 272
~~~ sh
# default behavior
$ git clone defunkt/repl
< git clone >
C
Chris Wanstrath 已提交
273

M
Mislav Marohnić 已提交
274 275 276 277 278
# opt into HTTPS:
$ git config --global hub.protocol https
$ git clone defunkt/repl
< https clone >
~~~
C
readme  
Chris Wanstrath 已提交
279 280


C
Chris Wanstrath 已提交
281 282
Meta
----
C
readme  
Chris Wanstrath 已提交
283

M
Mislav Marohnić 已提交
284 285 286
* Home: <https://github.com/github/hub>
* Bugs: <https://github.com/github/hub/issues>
* Authors: <https://github.com/github/hub/contributors>
M
Mislav Marohnić 已提交
287 288

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

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

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