GitHub Hub CLI
The GitHub Hub CLI (hub) is a command-line tool that wraps Git and provides more GitHub-specific functionality. It allows developers to interact with GitHub directly from their terminal, streamlining common workflows for both contributors and maintainers.
Hub CLI for Open-Source Contributors
As a contributor to open-source projects, hub simplifies tasks like cloning repositories, browsing project issues, and managing your contributions. It integrates seamlessly with your existing Git workflow.
# Clone your own project
$ git clone dotfiles
→ git clone git://github.com/YOUR_USER/dotfiles.git
# Clone another project
$ git clone github/hub
→ git clone git://github.com/github/hub.git
# See the current project's issues
$ git browse -- issues
→ open https://github.com/github/hub/issues
# Open another project's wiki
$ git browse mojombo/jekyll wiki
→ open https://github.com/mojombo/jekyll/wiki
Example Contributor Workflow
This workflow demonstrates how to contribute a new feature using hub:
$ git clone github/hub
$ cd hub
# Create a topic branch for your feature
$ git checkout -b feature
→ ( making changes ... )
$ git commit -m "done with feature"
# Fork the repository on GitHub
$ git fork
→ (forking repo on GitHub...)
→ git remote add YOUR_USER git://github.com/YOUR_USER/hub.git
# Push the changes to your new remote fork
$ git push YOUR_USER feature
# Open a pull request for the topic branch
$ git pull-request
→ (opens a text editor for your pull request message)
Hub CLI for Open-Source Maintainers
For project maintainers, hub offers powerful tools to manage contributions, review code, and integrate with GitHub's features. It helps in efficiently handling pull requests and managing repository updates.
# Fetch from multiple trusted forks, even if they don't yet exist as remotes
$ git 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
# Check out a pull request for review
$ git checkout https://github.com/github/hub/pull/134
→ (creates a new branch with the contents of the pull request)
# Directly apply all commits from a pull request to the current branch
$ git am -3 https://github.com/github/hub/pull/134
# Cherry-pick a GitHub URL
$ git cherry-pick https://github.com/xoebus/hub/commit/177eeb8
→ git remote add xoebus git://github.com/xoebus/hub.git
→ git fetch xoebus
→ git cherry-pick 177eeb8
# `am` can be better than cherry-pick since it doesn't create a remote
$ git am https://github.com/xoebus/hub/commit/177eeb8
# Open the GitHub compare view between two releases
$ git compare v0.9..v1.0
# Put compare URL for a topic branch to clipboard
$ git compare -u feature | pbcopy
# Create a repo for a new project
$ git init
$ git add . && git commit -m "It begins."
$ git create -d "My new thing"
→ (creates a new project on GitHub with the name of current directory)
$ git push origin master
Key Hub Commands for Maintainers
git fetch --multiple: Efficiently fetch from various forks.git checkout <pull_request_url>: Easily review pull requests locally.git am <pull_request_url>: Apply pull request commits directly.git compare: Generate comparison URLs for releases or branches.git create: Quickly create new GitHub repositories.
By leveraging the hub CLI, developers can significantly enhance their productivity when working with GitHub, making it an indispensable tool for both individual contributions and project management.