\newpage
GitHub is the most popular platform for hosting and collaborating on Git repositories. While the GitHub web interface is powerful, the GitHub Command Line Interface (CLI) enhances productivity by allowing you to manage repositories, issues, and pull requests directly from your terminal. This chapter focuses on using the GitHub CLI and best practices for team collaboration.
GitHub CLI is a command-line tool that integrates GitHub workflows into your terminal. With GitHub CLI, you can:
- Clone repositories.
- Create and merge pull requests.
- Manage issues and discussions.
- Perform actions on repositories without switching to the web interface.
sudo apt update
sudo apt install gh
Install using Homebrew:
brew install gh
Download the installer from cli.github.com.
Authenticate with your GitHub account:
gh auth login
Follow the interactive prompts to log in via the web or SSH.
-
Cloning a Repository
gh repo clone username/repository-name
-
Creating a New Repository
gh repo create repository-name
- Use
--public
or--private
to set visibility.
- Use
-
Viewing Repository Details
gh repo view
-
Creating a Pull Request
gh pr create --title "Add feature X" --body "Description of the feature."
-
Viewing Pull Requests
gh pr list
-
Checking Out a Pull Request
gh pr checkout pull-request-number
-
Merging a Pull Request
gh pr merge pull-request-number
-
Creating an Issue
gh issue create --title "Bug in feature Y" --body "Steps to reproduce the issue."
-
Viewing Issues
gh issue list
-
Closing an Issue
gh issue close issue-number
Engage with the community via GitHub Discussions:
gh discussion list
Manage notifications directly from the CLI:
gh notification list
Use descriptive and consistent names for branches, such as:
feature/add-login
bugfix/fix-crash
hotfix/update-logo
Write meaningful commit messages:
- Start with a verb: e.g., "Add," "Fix," "Update."
- Describe the change: e.g., "Fix crash on login screen."
- Review pull requests thoroughly.
- Use comments to suggest improvements.
- Approve or request changes as needed.
- Assign issues to team members.
- Use labels (e.g.,
bug
,enhancement
) for better tracking. - Close issues automatically with commit messages:
Fixes #123
Organize tasks using GitHub Project Boards:
- Create columns for stages (e.g., To Do, In Progress, Done).
- Move cards as tasks progress.
- Create a new repository using the CLI:
gh repo create my-project --public
- Clone the repository:
gh repo clone username/my-project
- Create a branch:
git checkout -b add-readme
- Add and commit a README file:
echo "# My Project" > README.md git add README.md git commit -m "Add README"
- Push the branch and create a pull request:
git push origin add-readme gh pr create --title "Add README" --body "Initial README file."
- Merge the pull request:
gh pr merge
In this chapter, you learned:
- How to use GitHub CLI for repository management, pull requests, and issues.
- Best practices for collaboration on GitHub.
GitHub CLI enhances productivity by streamlining GitHub workflows. In the next chapter, we’ll explore virtualization and containerization with tools like Docker.