hub: use GitHub from the command-line
Staying productive on the command-line
hub makes it easy to clone or create repositories, browse project pages, list known issues, ensure your local branches stay up to date, and share logs or code snippets via Gist.
hub clone dotfiles → git clone git://github.com/YOUR_USER/dotfiles.git hub clone github/hub → git clone git://github.com/github/hub.git cd myproject hub sync hub issue --limit 10 hub browse -- issues → open https://github.com/github/hub/issues hub browse rbenv/ruby-build wiki → open https://github.com/rbenv/ruby-build/wiki hub gist create --copy build.log → (the URL of the new private gist copied to clipboard)
Starting a new project has never been easier:
git init
git add .
git commit -m "And so, it begins."
hub create
→ (creates a new GitHub repository with the name of the current directory)
git push -u origin HEAD
Lowering the barrier to contributing to open-source
Whether you are beginner or an experienced contributor to open-source, hub makes it easier to fork repositories, check the CI status of a branch, and even submit pull requests from the same environment where you write & commit your code.
hub clone octocat/Spoon-Knife cd Spoon-Knife git checkout -b feature git commit -am "done with feature" hub fork --remote-name origin → (forking repo on GitHub...) → git remote add origin git@github.com:YOUR_USER/Spoon-Knife.git git push origin feature hub ci-status --verbose hub pull-request → (opens a text editor for your pull request message)
Automating tasks for fun and profit
Scripting is much easier now that you can list or create issues, pull requests, and GitHub Releases in the format of your choice.
hub issue --assignee YOUR_USER --labels urgent
hub pr list --limit 20 --base develop --format='%t [%H] | %U%n'
hub release create --copy -F release-notes.txt v2.3.0
→ (the URL of the new release copied to clipboard)
Drop down to the API level
Even if hub doesn't support the exact feature you need, you can use
hub api to manually make requests against any
GitHub API—even GraphQL—and
have hub handle authentication, JSON encoding/decoding, and pagination for you.
hub api repos/{owner}/{repo}/issues/123/comments --field body=@mycomment.txt
REPO="github/hub"
SHA="b0db79db"
hub api graphql --flat -f q="repo:$REPO type:pr $SHA" -f query='
query($q: String!) {
search(query: $q, type: ISSUE, first: 3) {
nodes {
... on PullRequest {
url
}
}
}
}
' | awk '/\.url/ { print $2 }'
See hub-api-utils for more examples.
Designed for open-source maintainers
Maintaining a project is easier when you can easily fetch from other forks, check out pull requests, close issues, and even cherry-pick commits by URL.
hub fetch mislav,cehoffman → git remote add mislav git://github.com/mislav/hub.git → git remote add cehoffman git://github.com/cehoffman/hub.git → git fetch --multiple mislav cehoffman hub pr checkout 134 → (creates a new branch with the contents of the pull request) git push hub issue update 134 --state closed hub am -3 https://github.com/github/hub/pull/134 hub cherry-pick https://github.com/xoebus/hub/commit/177eeb8 hub compare v0.9..v1.0 hub compare --url feature | pbcopy