logo
eng-flag

GitHub Cheat Sheet

Table of Contents

  1. Account Management
  2. Repository Operations
  3. Issues and Pull Requests
  4. GitHub Actions
  5. GitHub Pages
  6. GitHub CLI
  7. Collaboration Features
  8. GitHub Security
  9. GitHub Projects
  10. GitHub API
  11. Best Practices

Account Management

Create a new account

  1. Go to https://github.com
  2. Click "Sign up"
  3. Follow the prompts to create your account

Set up two-factor authentication (2FA)

  1. Go to Settings > Password and authentication
  2. Click "Enable two-factor authentication"
  3. Choose your preferred 2FA method (app or SMS)

Create an SSH key

  1. Open terminal
  2. Run: ssh-keygen -t ed25519 -C "your_email@example.com"
  3. Add the public key to your GitHub account in Settings > SSH and GPG keys

Repository Operations

Create a new repository

  1. Click "+" in the top-right corner
  2. Select "New repository"
  3. Fill in repository details and click "Create repository"

Fork a repository

  1. Navigate to the repository you want to fork
  2. 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

  1. Go to the repository's "Issues" tab
  2. Click "New issue"
  3. Fill in the title and description
  4. Click "Submit new issue"

Create a pull request

  1. Go to the repository's "Pull requests" tab
  2. Click "New pull request"
  3. Select the branch you want to merge
  4. Fill in the title and description
  5. Click "Create pull request"

Review a pull request

  1. Go to the "Pull requests" tab
  2. Click on the pull request you want to review
  3. Click "Files changed" to see the diff
  4. Leave comments or approve the changes

Merge a pull request

  1. Go to the pull request
  2. Click "Merge pull request" (if all checks pass)
  3. Confirm the merge

GitHub Actions

Create a new workflow

  1. In your repository, create a .github/workflows directory
  2. Create a new YAML file (e.g., ci.yml) in this directory
  3. 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

  1. Go to the "Actions" tab in your repository
  2. Click on a workflow to see its details and logs

GitHub Pages

Enable GitHub Pages

  1. Go to repository Settings
  2. Scroll down to "GitHub Pages" section
  3. Choose the source branch for your GitHub Pages site
  4. (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

  1. Go to repository Settings > Manage access
  2. Click "Invite a collaborator"
  3. Enter the username or email of the person you want to invite

Create a team

  1. Go to your organization page
  2. Click "Teams"
  3. Click "New team"
  4. Fill in team details and add members

Code review assignment

  1. Go to repository Settings > Branches
  2. Under "Branch protection rules", click "Add rule"
  3. Set up required reviewers for pull requests

GitHub Security

Enable Dependabot alerts

  1. Go to repository Settings > Security & analysis
  2. Enable "Dependabot alerts"

Set up code scanning

  1. Go to repository Settings > Security & analysis
  2. Set up "Code scanning" using GitHub Actions

Create a security policy

  1. In your repository, create a SECURITY.md file
  2. Define your security policy and how to report vulnerabilities

GitHub Projects

Create a new project

  1. Go to your profile or organization
  2. Click "Projects"
  3. Click "New project"
  4. Choose a template or start from scratch

Add items to a project

  1. Open your project
  2. Click "+ Add item"
  3. Create a new item or link an existing issue or pull request

Create custom fields

  1. In your project, click "+"
  2. Choose the field type (text, number, date, etc.)
  3. Name your field and configure its options

GitHub API

Generate a personal access token

  1. Go to Settings > Developer settings > Personal access tokens
  2. Click "Generate new token"
  3. 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

  1. Use meaningful commit messages: Write clear, concise commit messages that explain the changes made.

  2. Utilize branch protection rules: Set up branch protection rules to enforce code review and CI checks before merging.

  3. Keep repositories organized: Use labels, projects, and milestones to organize issues and pull requests.

  4. Document your project: Maintain a comprehensive README.md and CONTRIBUTING.md to help others understand and contribute to your project.

  5. Leverage GitHub Actions: Automate your workflow with GitHub Actions for CI/CD, testing, and other repetitive tasks.

  6. Use semantic versioning: When releasing new versions of your project, follow semantic versioning principles (MAJOR.MINOR.PATCH).

  7. Protect sensitive data: Never commit sensitive information like API keys or passwords. Use GitHub Secrets for GitHub Actions instead.

  8. Utilize GitHub Discussions: For open-source projects, enable GitHub Discussions to foster community engagement.

  9. Regular maintenance: Regularly update dependencies, address security alerts, and clean up old branches and closed issues.

  10. Code of Conduct: Implement a Code of Conduct for your project to establish community guidelines.

2024 © All rights reserved - buraxta.com