hub/README.md

386 строки
9.6 KiB
Markdown
Исходник Обычный вид История

2012-03-20 18:16:31 +04:00
git + hub = github
==================
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
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.
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
$ hub clone rtomayko/tilt
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
# expands to:
$ git clone git://github.com/rtomayko/tilt.git
~~~
2009-12-08 11:34:29 +03:00
2012-03-20 18:16:31 +04:00
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.
2010-03-06 05:05:44 +03:00
2009-12-08 11:34:29 +03:00
2012-03-20 18:16:31 +04:00
Installation
------------
2009-12-08 11:34:29 +03:00
2012-03-20 18:16:31 +04:00
Dependencies:
2009-12-08 11:34:29 +03:00
2012-03-20 18:16:31 +04:00
* **git 1.7.3** or newer
* **Ruby 1.8.6** or newer
2010-03-06 05:05:44 +03:00
2012-03-20 18:16:31 +04:00
### Homebrew
2009-12-09 07:10:12 +03:00
2012-03-20 18:16:31 +04:00
Installing on OS X is easiest with Homebrew:
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
$ brew install hub
~~~
2009-12-08 00:21:12 +03:00
2009-12-09 04:40:45 +03:00
### Standalone
2012-03-20 18:16:31 +04:00
`hub` is easily installed as a standalone script:
2009-12-08 12:12:32 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
$ curl http://defunkt.io/hub/standalone -sLo ~/bin/hub &&
chmod +x ~/bin/hub
~~~
2009-12-08 12:12:32 +03:00
2012-03-20 18:16:31 +04:00
Assuming "~/bin/" is in your `$PATH`, you're ready to roll:
2009-12-09 04:40:45 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
$ hub version
git version 1.7.6
hub version 1.8.3
~~~
### RubyGems
2009-12-09 08:28:15 +03:00
2012-03-20 18:16:31 +04:00
Though not recommended, hub can also be installed as a RubyGem:
2009-12-09 08:28:15 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
$ gem install hub
~~~
2009-12-09 08:28:15 +03:00
(It's not recommended for casual use because of the RubyGems startup
time. See [this gist][speed] for information.)
2010-01-24 01:10:03 +03:00
2012-03-20 18:16:31 +04:00
#### Standalone via RubyGems
2012-03-20 18:16:31 +04:00
~~~ sh
$ gem install hub
$ hub hub standalone > ~/bin/hub && chmod +x ~/bin/hub
~~~
This installs a standalone version which doesn't require RubyGems to
2012-03-20 18:16:31 +04:00
run, so it's faster.
2009-12-09 04:40:45 +03:00
### Source
2009-12-09 04:34:37 +03:00
You can also install from source:
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
$ git clone git://github.com/defunkt/hub.git
$ cd hub && rake install prefix=/usr/local
~~~
2009-12-08 00:21:12 +03:00
2011-03-20 23:06:24 +03:00
### 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:
2012-03-20 18:16:31 +04:00
$ echo $RUBYOPT
2011-03-20 23:06:24 +03:00
3. Check that your system Ruby is speedy:
2012-03-20 18:16:31 +04:00
$ time /usr/bin/env ruby -e0
2011-03-20 23:06:24 +03:00
If #3 is slow, it may be your [GC settings][gc].
2009-12-08 00:21:12 +03:00
2009-12-09 04:40:45 +03:00
Aliasing
--------
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
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.
2009-12-08 00:21:12 +03:00
2012-03-20 22:04:01 +04:00
`hub alias` displays instructions for the current shell. With the `-s` flag, it
outputs a script suitable for `eval`.
2009-12-09 07:08:36 +03:00
2012-03-20 22:04:01 +04:00
You should place this command in your `.bash_profile` or other startup script:
2009-12-09 07:08:36 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
2012-03-20 22:04:01 +04:00
eval "$(hub alias -s)"
2012-03-20 18:16:31 +04:00
~~~
2009-12-08 12:12:53 +03:00
### 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)
2009-12-08 00:21:12 +03:00
2009-12-08 11:18:55 +03:00
Commands
2009-12-08 00:21:12 +03:00
--------
2012-03-20 18:16:31 +04:00
Assuming you've aliased hub as `git`, the following commands now have
2009-12-09 04:40:45 +03:00
superpowers:
2009-12-08 00:21:12 +03:00
### git clone
$ git clone schacon/ticgit
2009-12-08 11:29:29 +03:00
> git clone git://github.com/schacon/ticgit.git
2009-12-08 00:21:12 +03:00
$ git clone -p schacon/ticgit
2009-12-08 11:29:29 +03:00
> git clone git@github.com:schacon/ticgit.git
2009-12-08 00:21:12 +03:00
$ git clone resque
> git clone git@github.com/YOUR_USER/resque.git
2009-12-08 00:21:12 +03:00
### git remote add
$ git remote add rtomayko
2009-12-08 11:29:29 +03:00
> git remote add rtomayko git://github.com/rtomayko/CURRENT_REPO.git
2009-12-09 15:39:23 +03:00
$ git remote add -p rtomayko
2009-12-08 11:29:29 +03:00
> git remote add rtomayko git@github.com:rtomayko/CURRENT_REPO.git
2009-12-08 00:21:12 +03:00
$ git remote add origin
> git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git
### 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
### 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
2011-10-20 17:40:40 +04:00
### git am, git apply
$ 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
2011-10-20 17:40:40 +04:00
$ 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
### git fork
$ git fork
[ repo forked on GitHub ]
2010-04-07 21:11:52 +04:00
> git remote add -f YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
2011-10-20 21:32:57 +04:00
### git pull-request
2011-10-21 05:07:30 +04:00
# while on a topic branch called "feature":
$ git pull-request
[ opens text editor to edit title & body for the request ]
2011-10-21 05:07:30 +04:00
[ opened pull request on GitHub for "YOUR_USER:feature" ]
2011-10-20 21:32:57 +04:00
# explicit title, pull base & head:
$ git pull-request "I've implemented feature X" -b defunkt:master -h mislav:feature
2011-10-20 21:32:57 +04:00
2011-11-22 17:11:15 +04:00
$ git pull-request -i 123
2011-10-21 05:07:30 +04:00
[ attached pull request to issue #123 ]
2011-10-20 21:32:57 +04:00
### 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 --track -B mislav-feature mislav/feature
# $ git checkout https://github.com/defunkt/hub/pull/73 custom-branch-name
2010-05-13 00:31:52 +04:00
### git create
$ git create
[ repo created on GitHub ]
2010-05-13 00:31:52 +04:00
> git remote add origin git@github.com:YOUR_USER/CURRENT_REPO.git
# 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
2009-12-08 00:21:12 +03:00
### git init
2009-12-08 08:28:38 +03:00
$ git init -g
2009-12-08 11:29:29 +03:00
> git init
> git remote add origin git@github.com:YOUR_USER/REPO.git
2009-12-08 11:29:29 +03:00
2009-12-24 21:32:39 +03:00
### git push
$ git push origin,staging,qa bert_timeout
> git push origin bert_timeout
> git push staging bert_timeout
> git push qa bert_timeout
### git browse
$ git browse
2011-02-28 18:38:52 +03:00
> open https://github.com/YOUR_USER/CURRENT_REPO
$ git browse -- commit/SHA
> open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA
$ git browse -- issues
2011-02-28 18:38:52 +03:00
> open https://github.com/YOUR_USER/CURRENT_REPO/issues
$ git browse schacon/ticgit
> open https://github.com/schacon/ticgit
$ git browse schacon/ticgit commit/SHA
> open https://github.com/schacon/ticgit/commit/SHA
$ git browse resque
> open https://github.com/YOUR_USER/resque
$ git browse resque network
> open https://github.com/YOUR_USER/resque/network
### git compare
$ git compare refactor
> open https://github.com/CURRENT_REPO/compare/refactor
$ git compare 1.0..1.1
> open https://github.com/CURRENT_REPO/compare/1.0...1.1
$ git compare -u fix
> (https://github.com/CURRENT_REPO/compare/fix)
$ git compare other-user patch
> open https://github.com/other-user/REPO/compare/patch
2010-04-22 02:42:17 +04:00
### git submodule
2010-04-22 02:42:17 +04:00
$ 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
$ hub submodule add -b ryppl ryppl/pip vendor/pip
2010-04-22 02:42:17 +04:00
> git submodule add -b ryppl git://github.com/ryppl/pip.git vendor/pip
2009-12-08 11:29:29 +03:00
### git help
$ git help
> (improved git help)
2009-12-10 23:59:01 +03:00
$ git help hub
> (hub man page)
2009-12-08 00:21:12 +03:00
2012-03-20 18:16:31 +04:00
Configuration
-------------
### GitHub username & token
2009-12-09 04:40:45 +03:00
2012-03-20 18:16:31 +04:00
To get the most out of hub, you'll want to ensure your GitHub login
is stored locally in your Git config or environment variables.
2009-12-09 04:40:45 +03:00
To test it run this:
$ git config --global github.user
If you see nothing, you need to set the config setting:
2009-12-09 08:14:05 +03:00
$ git config --global github.user YOUR_USER
2009-12-09 04:40:45 +03:00
For commands that require write access to GitHub (such as `fork`), you'll want to
setup "github.token" as well. See [GitHub config guide][2] for more information.
2009-12-09 04:40:45 +03:00
If present, environment variables `GITHUB_USER` and `GITHUB_TOKEN` override the
values of "github.user" and "github.token".
2009-12-09 04:40:45 +03:00
2012-03-20 18:16:31 +04:00
### HTTPS insted of git protocol
2009-12-24 21:55:07 +03:00
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".
2009-12-24 21:55:07 +03:00
2012-03-20 18:16:31 +04:00
~~~ sh
# default behavior
$ git clone defunkt/repl
< git clone >
2009-12-24 21:55:07 +03:00
2012-03-20 18:16:31 +04:00
# opt into HTTPS:
$ git config --global hub.protocol https
$ git clone defunkt/repl
< https clone >
~~~
2009-12-08 00:21:12 +03:00
2009-12-08 11:18:55 +03:00
Contributing
------------
2012-03-20 18:16:31 +04:00
These instructions assume that you already have hub installed and aliased as
`git` (see "Aliasing").
2011-10-27 15:48:42 +04:00
1. Clone hub:
2012-03-20 18:16:31 +04:00
`git clone defunkt/hub && cd hub`
1. Install development dependencies:
`bundle install`
2. Verify that existing tests pass:
`bundle exec rake`
2011-10-27 15:48:42 +04:00
3. Create a topic branch:
2012-03-20 18:16:31 +04:00
`git checkout -b feature`
4. **Make your changes.** (It helps a lot if you write tests first.)
2011-10-27 15:48:42 +04:00
5. Verify that tests still pass:
2012-03-20 18:16:31 +04:00
`bundle exec rake`
2011-10-27 15:48:42 +04:00
6. Fork hub on GitHub (adds a remote named "YOUR_USER"):
`git fork`
7. Push to your fork:
2012-03-20 18:16:31 +04:00
`git push -u YOUR_USER feature`
2011-10-27 15:48:42 +04:00
8. Open a pull request describing your changes:
`git pull-request`
2009-12-08 11:18:55 +03:00
2009-12-08 08:28:38 +03:00
Meta
----
2009-12-08 00:21:12 +03:00
2011-10-27 15:48:42 +04:00
* Home: <https://github.com/defunkt/hub>
* Bugs: <https://github.com/defunkt/hub/issues>
* Gem: <https://rubygems.org/gems/hub>
2012-03-20 18:16:31 +04:00
* Authors: <https://github.com/defunkt/hub/contributors>
### Prior art
2009-12-08 11:18:55 +03:00
2012-03-20 18:16:31 +04:00
These projects also aim to either improve git or make interacting with
GitHub simpler:
2009-12-08 11:18:55 +03:00
2012-03-20 18:16:31 +04:00
* [eg](http://www.gnome.org/~newren/eg/)
* [github-gem](https://github.com/defunkt/github-gem)
2009-12-08 11:18:55 +03:00
2010-01-24 01:10:03 +03:00
[speed]: http://gist.github.com/284823
[2]: http://help.github.com/set-your-user-name-email-and-github-token/
2011-03-22 21:26:40 +03:00
[gc]: https://twitter.com/brynary/status/49560668994674688