When working on a project, we usually write code locally and track all changes through the Git command line. If you want to host or open source, you can also use Git to push the entire project directly to GitHub.

Generally speaking, Git is mainly controlled through the command line, and the three commands of add, commit, and push are completed in one go. Of course, Git can also view the status of code files or trace back historical code and so on. Since Git, command line tools have looked a lot cooler.


Git minimalist tutorial: The first step is to add the modified code file, the second step is to commit the changes to the local code base, and the third step is to push the local code base to the remote code base.

After we submit the local code to GitHub, we can view various interactive information on the GitHub website, such as issues raised by other developers, or submitted code merge requests. However, if we can view and process this information directly on the command line, then this must be very cool. From Git to GitHub, the command line can provide one-stop service.

Recently, GitHub has fulfilled this imagination. It has newly released a new command line tool "GitHub CLI", which can seamlessly connect with GitHub. As the blog puts it: "The gh command will bring GitHub's operating experience to the command line."

This command-line toolkit can now be installed on macOS, Windows, and Linux. Although the GitHub CLI is still in beta, it is still very friendly from our experience. In addition, despite being a new project, it already has a 4.8K Star volume, and it has grown by 1.3K in just one day since its launch.

Get started with the GitHub CLI

Because we tried the macOS of the system, according to the official documentation, just use Homebrew directly, no additional operations are required. The first question after installation is, how does it know what my GitHub account is? Sure enough, authorization is required before running the command. But this authorization is also very simple. Just click OK on the GitHub page, and gh will automatically log in to our GitHub account.

Go to the local GitHub project later, and now the gh command is fine. As follows, we first submit an issue interactively. Issue's body needs to be edited by nano.

Yes, the interactive issue will finally open the webpage, preview and submit. Of course, we can also choose to submit directly from the command line. In the GitHub blog and documentation, we can find more ways to play, and we will introduce some of them below.

GitHub first introduces the usage of Issue and Pull Requests tasks, because most developers deal with them every day. The following sections will show them in five steps. At the same time, if we submit code or perform other operations on an open source project, the gh command will give you a different experience.

gh manual: https://cli.github.com/manual/

Filter issue

Now, let's find an open source project that wants to do something with it and download it locally. If we want to look at the entries that the maintainers want to help, then we can use gh to filter different issues. Issues related to "help-wanted" will be filtered as shown below:

Take a quick look

If you find a bug that you can solve, use gh to quickly display the details of the issue on the webpage.

Create Pull Request

Create a branch and submit some code to fix the bug mentioned in the previous issue, then you can submit a PR to share your contribution:

If you use the GitHub CLI to create a Pull Request, and you didn't fork the project before, the command tool will automatically fork it. The command tool will push the branch up and submit a PR to wait for merge changes.

View PR status

Wait until the next day to see what happened to the submitted PR. The gh command can show the status of the Pull Request and preview it:

Check Pull Request

Once the project maintainer sees the PR you submitted and gives feedback, we may have switched branches. So, you can use gh to check the Pull Request branch:

Fix the code, push the code, and merge the code. Now you have the basic operations of the GitHub CLI. Later, as command line tools become more and more powerful, maybe more and more convenient GitHub capabilities can be added, such as browsing code and so on.

Last modified: February 15, 2020

Author

Comments

Leave a Reply