Coder Social home page Coder Social logo

mislav / hub Goto Github PK

View Code? Open in Web Editor NEW
22.7K 579.0 2.2K 7.16 MB

A command-line tool that makes git easier to use with GitHub.

Home Page: https://hub.github.com/

License: MIT License

Ruby 3.97% Go 49.52% Shell 5.41% Batchfile 0.29% Makefile 0.33% Gherkin 39.89% HTML 0.23% Dockerfile 0.08% Vim Script 0.28%
go homebrew git github-api pull-request

hub's Introduction

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.

For an official, potentially more user-friendly command-line interface to GitHub, see cli.github.com and this comparison.

This repository and its issue tracker is not for reporting problems with GitHub.com web interface. If you have a problem with GitHub itself, please contact Support.

Usage

$ hub clone rtomayko/tilt
#=> git clone https://github.com/rtomayko/tilt.git

# or, if you prefer the SSH protocol:
$ git config --global hub.protocol ssh
$ hub clone rtomayko/tilt
#=> git clone [email protected]:rtomayko/tilt.git

See usage examples or the full reference documentation to see all available commands and flags.

hub can also be used to make shell scripts that directly interact with the GitHub API.

hub can be safely aliased as git, so you can type $ git <command> in the shell and have it expanded with hub features.

Installation

The hub executable has no dependencies, but since it was designed to wrap git, it's recommended to have at least git 1.7.3 or newer.

platform manager command to run
macOS, Linux Homebrew brew install hub
macOS, Linux Nix nix-env -i hub
Windows Scoop scoop install hub
Windows Chocolatey choco install hub
Fedora Linux DNF sudo dnf install hub
Arch Linux pacman sudo pacman -S hub
FreeBSD pkg(8) pkg install hub
Debian, Ubuntu apt(8) sudo apt install hub
Ubuntu Snap We do not recommend installing the snap anymore.
openSUSE Zypper sudo zypper install hub
Void Linux xbps sudo xbps-install -S hub
Gentoo Portage sudo emerge dev-vcs/hub
any conda conda install -c conda-forge hub

Packages other than Homebrew are community-maintained (thank you!) and they are not guaranteed to match the latest hub release. Check hub version after installing a community package.

Standalone

hub can be easily installed as an executable. Download the latest binary for your system and put it anywhere in your executable path.

GitHub Actions

hub is ready to be used in your GitHub Actions workflows:

steps:
- uses: actions/checkout@v2

- name: List open pull requests
  run: hub pr list
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Note that the default secrets.GITHUB_TOKEN will only work for API operations scoped to the repository that runs this workflow. If you need to interact with other repositories, generate a Personal Access Token with at least the repo scope and add it to your repository secrets.

Source

Prerequisites for building from source are:

Clone this repository and run make install:

git clone \
  --config transfer.fsckobjects=false \
  --config receive.fsckobjects=false \
  --config fetch.fsckobjects=false \
  https://github.com/github/hub.git

cd hub
make install prefix=/usr/local

Aliasing

Some hub features feel best when it's aliased as git. This is not dangerous; your normal git commands will all work. hub merely adds some sugar.

hub alias displays instructions for the current shell. With the -s flag, it outputs a script suitable for eval.

You should place this command in your .bash_profile or other startup script:

eval "$(hub alias -s)"

PowerShell

If you're using PowerShell, you can set an alias for hub by placing the following in your PowerShell profile (usually ~/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1):

Set-Alias git hub

A simple way to do this is to run the following from the PowerShell prompt:

Add-Content $PROFILE "`nSet-Alias git hub"

Note: You'll need to restart your PowerShell console in order for the changes to be picked up.

If your PowerShell profile doesn't exist, you can create it by running the following:

New-Item -Type file -Force $PROFILE

Shell tab-completion

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

Meta

hub's People

Contributors

andreasbaumann avatar apjanke avatar blueyed avatar calavera avatar cehoffman avatar darrenwee avatar defunkt avatar dgryski avatar eli-schwartz avatar eljobe avatar elliott-beach avatar ganmacs avatar jaymzh avatar jfahrer avatar jsoref avatar justinweiss avatar kfcampbell avatar mattwindsor91 avatar mislav avatar nex3 avatar owenthereal avatar patheticpat avatar pcorpet avatar shigemk2 avatar sionleroux avatar srafi1 avatar stephencelis avatar tgkokk avatar walles avatar whuang8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hub's Issues

hub browse with no arguments

Currently, hub browse needs an argument, because without one it takes you to "CURRENT_USER/browse", which is a bug.

I've changed hub browse to take you to the GitHub page of the repo in current directory. The changes are in mislav@browse.

hub assumes the name of the repository to be the name of the current directory

For example:

$ cd /usr/local/Library/Formula
$ hub remote add akahn
$ cat ../../.git/config
[remote "akahn"]
    url = git://github.com/akahn/Formula.git
    fetch = +refs/heads/*:refs/remotes/akahn/*

That remote url is going to be problematic. To solve this, hub needs to figure out what the name of the repository is, and construct the remote url based on that.

I'll take a look and see if I can come up with a solution.

"browse" is broken: command not found: type -t xdg-open

browse_command calls command, but that fails in both zsh and bash for me:
$ git browse
/home/user/bin/hub:648: command not found: type -t xdg-open
/home/user/bin/hub:648: command not found: type -t cygstart
Please set $BROWSER to a web launcher to use this command.

The same with zsh.

The fix appears to be using which instead, where I will provide a topic branch for in a moment.

Bash completion broken

When setting hub as alias of git the bash completion for most git commands (eg. checkout) breaks. Not sure if other shells are also affected.

To clarify: It fails to complete the word "checkout". Once that is manually typed the completion works as expected.

support public HTTP URLs

For those of us behind corporate proxies, git:// URLs may not work. I created a branch that supports a git config property called github.use_http_for_public. Setting that property to true will cause hub to use HTTP URLs.

Assumes ".git" on end of git URLs

The regular expression to match a git repository enforces a ".git" on the end of it. This suffix is optional, and causes failures to match repository URLs without it on the end. Patch included.

diff --git a/lib/hub/context.rb b/lib/hub/context.rb
index c583d28..8b226ed 100644
--- a/lib/hub/context.rb
+++ b/lib/hub/context.rb
@@ -12,7 +12,7 @@ module Hub
     REMOTES = Hash.new do |cache, remote|
       url = GIT_CONFIG["config remote.#{remote}.url"]

-      if url && url.to_s =~ %r{\bgithub\.com[:/](.+)/(.+).git$}
+      if url && url.to_s =~ %r{\bgithub\.com[:/](.+)/(.+?)(.git)?$}
         cache[remote] = { :user => $1, :repo => $2 }
       else
         cache[remote] = { }

git fetch improvements

I don't want to type git remote add -f USER, I want to type git fetch USER and have the remote added automatically if it's not there.

hub command fails with MacOSX default ruby (Snow Leopard)

nov@argentea:~$ hub
/Library/Ruby/Gems/1.8/gems/git-hub-0.1.2/lib/hub/standalone.rb:20:in read': No such file or directory - man/hub.1 (Errno::ENOENT) from /Library/Ruby/Gems/1.8/gems/git-hub-0.1.2/lib/hub/standalone.rb:20 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' from /Library/Ruby/Gems/1.8/gems/git-hub-0.1.2/lib/hub.rb:5 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' from /Library/Ruby/Gems/1.8/gems/git-hub-0.1.2/bin/hub:6 from /usr/bin/hub:19:inload'
from /usr/bin/hub:19

Remove `git browse project`

I don't like it. All hub commands should operate on the current repo only, with the exception of the clone subcommand. Just like git.

hub init -g error

loki:bin wolverian$ hub init -g
fatal: Not a git repository (or any of the parent directories): .git    
/Users/wolverian/Applications/Homebrew/bin/hub:540:in `remotes': undefined method `split' for nil:NilClass (NoMethodError)
from /Users/wolverian/Applications/Homebrew/bin/hub:554:in `default_remote'
from /Users/wolverian/Applications/Homebrew/bin/hub:511:in `repo_name'
from /Users/wolverian/Applications/Homebrew/bin/hub:577:in `github_url'
from /Users/wolverian/Applications/Homebrew/bin/hub:175:in `init'
from /Users/wolverian/Applications/Homebrew/bin/hub:609:in `initialize'
from /Users/wolverian/Applications/Homebrew/bin/hub:613:in `new'
from /Users/wolverian/Applications/Homebrew/bin/hub:613:in `execute'
from /Users/wolverian/Applications/Homebrew/bin/hub:646:in `<main>'

Updated to use ronn v0.5

Because of the name change of ron to ronn it's now difficult for someone who didn't have the old version of ron to build the documentation to test changes. This branch changes the documentation and Rakefile to be compatible with the current gem version of ronn, v0.5:

http://github.com/xoebus/hub/tree/ronn

Homebrew integration

I totally agree that rubygems isn't the prefer method when installing hub. (totally sucks with rvm switching).

In addition to curl > hub, the other preferred method should be the much loved homebrew.

I already submitted a patch for it. So it should be in shortly. Plus it installs the man pages, w00t.

Homebrew <3 Hub ticket: http://github.com/mxcl/homebrew/issues/#issue/199

I'd be nice to have a "rake install PREFIX=/usr/local" task in hub. If you think its a good idea, I'll whip up a patch.

Tracked branches and browsing to subpages

Hey there,

I've added some features I found useful in my workflow. It's best to read the commit message: bae0d72

Example workflow:

$ git push -u mislav topic
# pushes to "mislav/topic" branch, sets up tracking
$ git compare -u | pbcopy
# copy the link to the topic branch to clipboard
$ git browse defunkt/hub issues
# open up a new issue, paste the link

In fact, this is exactly what I used to submit this issue ;)

This is a part of my "tracking" branch which has tons of other improvements I did in order to implement this with least code. Be sure to read about new Hub::Context 4b7c3db

The topic branch also includes a patch for #33

Typo in README.md

Unless I'm misunderstanding something, I think this is a typo/copy-paste error:

$ git remote add -p pjhyett
> git remote add rtomayko [email protected]:rtomayko/CURRENT_REPO.git

And should be:

$ git remote add -p pjhyett
> git remote add pjhyett [email protected]:pjhyett/CURRENT_REPO.git

clipboard command

very often I want to share my last commit link with coworkers via IM/mail

would be very convenient to have command which prints url and places it to clipboard:
git clip <what>

where "what" may be:

  • commit = url pointing to last commit on github
  • home = url pointing to project home
  • issues = url pointing to project's issues page
  • branch = points to branch
  • wiki = ...
  • ...

the most useful should be the first one, which should be the default "git clip"

what do you think guys?

git cherry-pick

Allow cherry-picking of GitHub URLs.

#!/usr/bin/env ruby
# Usage:
#   gpick http://github.com/cmelbye/github-services/commit/4f1559a82c9aa710baa3497f913ed3d9a666ced7

if ARGV[0] =~ /github\.com\/([^\/]+)\/.+\/commit\/(.+)/
  user = $1
  sha = $2
end

exec "hub remote add #$1; git fetch #$1; git cherry-pick #$2"

Compare command

I have implemented a compare command which can be used to open
a compare view page in the default browser. It can also just print out the URL for copy and paste.
You can specify the start to end range and also which "remote" repository to use.

See http://github.com/joshthecoder/hub/compare/compare for more details.

Hub breaks git auto-completion in zsh

When git is aliased to hub, pressing <Tab> after typing git doesn't trigger git command auto-completion โ€” it just trigger the regular zsh file/directory completion.

Honor git global pagination options/behavior

(I guess it's usually "paging", not "pagination"...)

Running git (git help, and git --help) without any more arguments displays the usage without a pager. Running hub, however, doesn't honor this. Writing hub --no-pager just sends execution straight to git (as do --paginate and -p). This commit fixes the behavior:

http://github.com/stephencelis/hub/commit/ed49567cd36a2880de9ba3a65892c45557d52594

Not sure if the execution is desirable (i.e., adding the @no_pager variable), but it's the least invasive without parsing through all the global options.

Use "-p" for ssh access by default / doc

Is there any reason you do not want "-p" to be the default, with e.g. hub clone?

Using "-p" allows you to easily push, which this won't work with a http clone/push url.

I suggest using another option to disable ssh instead.

Also, "-p" is not documented anywhere, except for the examples and in the source itself, as far as I can see.

Help Output Rework

I love the help output - I did this once before for core Git and it wasn't accepted because it was bigger than 24x80 or something. So, I redid the help output here to be more like I had originally done it, which I think is a bit clearer - I also changed several of the descriptions to be a bit clearer and more uniform.

schacon@help_update

browse: crash when not in repository (NoMethodError)

"git browse" fails rather ugly when not in a git repository.

I think there should be only one "fatal" error and no NoMethodError at all.

% cd /tmp
% git browse
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
/home/user/bin/hub:539:in `remotes': private method `split' called for nil:NilClass (NoMethodError)
    from /home/user/bin/hub:553:in `default_remote'
    from /home/user/bin/hub:549:in `current_remote'
    from /home/user/bin/hub:506:in `repo_user'
    from /home/user/bin/hub:222:in `browse'
    from /home/user/bin/hub:404:in `browse_command'
    from /home/user/bin/hub:215:in `browse'
    from /home/user/bin/hub:610:in `send'
    from /home/user/bin/hub:610:in `initialize'
    from /home/user/bin/hub:614:in `new'
    from /home/user/bin/hub:614:in `execute'
    from /home/user/bin/hub:647

MD5 mismatch

When trying to install with brew, the error "MD5 mismatch" occurs.

Provide better "live" documentation of the $BROWSER variable requirement

The browse and compare commands both try to launch a browser.

On non-macs, where the open(1) command isn't available (or is a symlink to openvt), those commands fail if no BROWSER var is defined.

The docs currently say the command "[uses] open(1) or the BROWSER env variable", but it's actually the other way around. open(1) is the fallback if $BROWSER isn't defined.

For those that don't read the docs, it would be nice to print a helper message (similar to hub alias) if the browser-launching command failed. In my case, "open" returns 1 and prints "Couldn't get a file descriptor referring to the console" to stderr.

Hub browse should open the current branch

Right now hub browse without arguments opens the current repository at master on GitHub. I think it should open the current branch on GitHub. Thoughts on this?

What makes this complicated is that often a local branch won't be on GitHub. But it probably isn't hard to check if the current branch is also on a remote. Then hub could browse the current branch if it has been pushed, and continue the current behavior if not.

Alex

Even better respect git paging options.

A few small fixes:

Ruby 1.9 doesn't like it when you call "first" on a string:

http://github.com/stephencelis/hub/commit/32d4d38857d8456de33e8efb290f365bb8f47885

git sets pager to "cat" when the pager is an empty string:

http://github.com/stephencelis/hub/commit/36ee4529c48fba56d31cb85b478e76054a7b0d4d

And here's the fix for your comment here (http://github.com/stephencelis/hub/commit/ed49567cd36a2880de9ba3a65892c45557d52594#comments):

http://github.com/stephencelis/hub/commit/b523c4251274460e5539b4923d2fdfa83a7844d1

I like not depending on the Runner's implementation, but [-p|--paginate|--no-pager] still, in the meantime, immediately bomb out to git.

typo in man page

fix:
diff --git a/man/hub.1 b/man/hub.1
index 2e78620..9e772d3 100644
--- a/man/hub.1
+++ b/man/hub.1
@@ -147,7 +147,7 @@ $ git remote add -p rtomayko
> git remote add rtomayko [email protected]:rtomayko/CURRENT_REPO.git

 $ git remote add origin
-> git remote add origingit://github.com/YOUR_USER/CURRENT_REPO.git
+> git remote add origin git://github.com/YOUR_USER/CURRENT_REPO.git

Hub on Windows?

Hi, I was wondering if there is a way to get Hub to run on Windows?

hub pages

I'm wondering if you think this will be useful, I tend to do this often with projects that have a gh-pages branch:

git checkout gh-pages
git clean -dfx

so maybe that could be wrapped up as

hub pages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.