GitHub Cheat Sheet
Table of Contents
- Account Management
- Repository Operations
- Issues and Pull Requests
- GitHub Actions
- GitHub Pages
- GitHub CLI
- Collaboration Features
- GitHub Security
- GitHub Projects
- GitHub API
- Best Practices
Account Management
Create a new account
- Go to https://github.com
- Click "Sign up"
- Follow the prompts to create your account
Set up two-factor authentication (2FA)
- Go to Settings > Password and authentication
- Click "Enable two-factor authentication"
- Choose your preferred 2FA method (app or SMS)
Create an SSH key
- Open terminal
- Run:
ssh-keygen -t ed25519 -C "your_email@example.com"
- Add the public key to your GitHub account in Settings > SSH and GPG keys
Repository Operations
Create a new repository
- Click "+" in the top-right corner
- Select "New repository"
- Fill in repository details and click "Create repository"
Fork a repository
- Navigate to the repository you want to fork
- Click the "Fork" button in the top-right corner
Clone a repository
git clone https://github.com/username/repository.git
Create a new branch
git checkout -b new-branch-name
Push changes to GitHub
git push origin branch-name
Issues and Pull Requests
Create a new issue
- Go to the repository's "Issues" tab
- Click "New issue"
- Fill in the title and description
- Click "Submit new issue"
Create a pull request
- Go to the repository's "Pull requests" tab
- Click "New pull request"
- Select the branch you want to merge
- Fill in the title and description
- Click "Create pull request"
Review a pull request
- Go to the "Pull requests" tab
- Click on the pull request you want to review
- Click "Files changed" to see the diff
- Leave comments or approve the changes
Merge a pull request
- Go to the pull request
- Click "Merge pull request" (if all checks pass)
- Confirm the merge
GitHub Actions
Create a new workflow
- In your repository, create a .github/workflows directory
- Create a new YAML file (e.g., ci.yml) in this directory
- Define your workflow using GitHub Actions syntax
Example workflow:
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo Hello, world!
View workflow results
- Go to the "Actions" tab in your repository
- Click on a workflow to see its details and logs
GitHub Pages
Enable GitHub Pages
- Go to repository Settings
- Scroll down to "GitHub Pages" section
- Choose the source branch for your GitHub Pages site
- (Optional) Choose a theme or set a custom domain
Access your GitHub Pages site
GitHub CLI
Install GitHub CLI
Authenticate with GitHub CLI
gh auth login
Create a repository
gh repo create repo-name
Create an issue
gh issue create --title "Issue title" --body "Issue description"
Create a pull request
gh pr create --title "PR title" --body "PR description"
Collaboration Features
Invite collaborators
- Go to repository Settings > Manage access
- Click "Invite a collaborator"
- Enter the username or email of the person you want to invite
Create a team
- Go to your organization page
- Click "Teams"
- Click "New team"
- Fill in team details and add members
Code review assignment
- Go to repository Settings > Branches
- Under "Branch protection rules", click "Add rule"
- Set up required reviewers for pull requests
GitHub Security
Enable Dependabot alerts
- Go to repository Settings > Security & analysis
- Enable "Dependabot alerts"
Set up code scanning
- Go to repository Settings > Security & analysis
- Set up "Code scanning" using GitHub Actions
Create a security policy
- In your repository, create a SECURITY.md file
- Define your security policy and how to report vulnerabilities
GitHub Projects
Create a new project
- Go to your profile or organization
- Click "Projects"
- Click "New project"
- Choose a template or start from scratch
Add items to a project
- Open your project
- Click "+ Add item"
- Create a new item or link an existing issue or pull request
Create custom fields
- In your project, click "+"
- Choose the field type (text, number, date, etc.)
- Name your field and configure its options
GitHub API
Generate a personal access token
- Go to Settings > Developer settings > Personal access tokens
- Click "Generate new token"
- Select scopes and create the token
Make an API request
Using curl:
curl -H "Authorization: token YOUR_TOKEN" https://api.github.com/user
Using GitHub CLI:
gh api user
Best Practices
-
Use meaningful commit messages: Write clear, concise commit messages that explain the changes made.
-
Utilize branch protection rules: Set up branch protection rules to enforce code review and CI checks before merging.
-
Keep repositories organized: Use labels, projects, and milestones to organize issues and pull requests.
-
Document your project: Maintain a comprehensive README.md and CONTRIBUTING.md to help others understand and contribute to your project.
-
Leverage GitHub Actions: Automate your workflow with GitHub Actions for CI/CD, testing, and other repetitive tasks.
-
Use semantic versioning: When releasing new versions of your project, follow semantic versioning principles (MAJOR.MINOR.PATCH).
-
Protect sensitive data: Never commit sensitive information like API keys or passwords. Use GitHub Secrets for GitHub Actions instead.
-
Utilize GitHub Discussions: For open-source projects, enable GitHub Discussions to foster community engagement.
-
Regular maintenance: Regularly update dependencies, address security alerts, and clean up old branches and closed issues.
-
Code of Conduct: Implement a Code of Conduct for your project to establish community guidelines.