hub: use GitHub from the command-line
hub is an extension to command-line git that
helps you do everyday GitHub tasks without ever leaving the terminal.
Read the full documentation: man hub, or
visit this project on GitHub.
brew install hub
hub version
git version 2.25.0
hub version 2.14.2
git config --global hub.protocol https
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 [email protected]: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
Using GitHub for work
Save time at work by opening pull requests for code reviews and
pushing to multiple remotes at once. Even GitHub Enterprise
is supported.
git config --global --add hub.host my.example.org
hub issue transfer 123 NEWREPO
git push origin feature
hub pull-request --copy -F prepared-message.md
â (the URL of the new pull request copied to clipboard)
hub push production,staging
See the full reference documentation to learn more.