Github
General
Github Workflow

GitHub Workflow Documentation

Introduction

GitHub is a cloud-based platform for version control and collaboration, enabling developers to manage Git repositories and work together on projects efficiently. This documentation provides an in-depth guide to using GitHub effectively.

Creating a Repository

To create a new repository on GitHub:

  1. Go to GitHub (opens in a new tab) and log in.
  2. Click the + button in the top right and select New repository.
  3. Enter a repository name and description.
  4. Choose visibility (public or private).
  5. Initialize with a README (optional).
  6. Click Create repository.

Cloning a Repository

To clone a repository to your local machine:

git clone <repository-url>

Example:

git clone https://github.com/user/repository.git

Working with Branches

Creating a New Branch

git checkout -b <branch-name>

Switching Branches

git checkout <branch-name>

Pushing a Branch

git push origin <branch-name>

Committing and Pushing Changes

Adding and Committing Files

git add .
git commit -m "Commit message"

Pushing Changes to GitHub

git push origin <branch-name>

Creating a Pull Request (PR)

  1. Navigate to the repository on GitHub.
  2. Click Pull requests > New pull request.
  3. Select the base and compare branches.
  4. Add a title and description.
  5. Click Create pull request.

Merging a Pull Request

  1. Go to the pull request on GitHub.
  2. Click Merge pull request.
  3. Confirm the merge.
  4. Delete the branch (optional).

Fetching and Pulling Updates

Fetching Updates (Without Merging)

git fetch origin

Pulling Updates (With Merging)

git pull origin <branch-name>

Issues and Discussions

Creating an Issue

  1. Navigate to the repository.
  2. Click Issues > New issue.
  3. Add a title, description, and relevant labels.
  4. Click Submit new issue.

Participating in Discussions

  1. Navigate to the Discussions tab of a repository.
  2. Click on an existing discussion or start a new one.

Using GitHub Actions

Setting Up a Workflow

  1. Go to the Actions tab in the repository.
  2. Select a pre-built workflow or create a new .github/workflows/main.yml file.
  3. Define the workflow steps and triggers.
  4. Commit the workflow file to trigger automation.

Conclusion

This guide provides an overview of GitHub workflows. For more details, visit GitHub Docs (opens in a new tab).


Creating a GitHub Workflow

Workflows automate tasks like running tests, building code, or deploying applications. This guide provides a step-by-step approach to setting up a GitHub Workflow.

Step 1: Set Up the Workflow Directory

Navigate to your repository and create a .github/workflows directory:

mkdir -p .github/workflows

Step 2: Define a Workflow in main.yml

Create a workflow file at .github/workflows/main.yml with the following content:

name: "CI Pipeline"
 
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
 
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      
      - name: Run custom action
        uses: ./.github/actions/my-action
        with:
          message: "Hello from the workflow!"

Step 3: Commit and Push the Workflow

Once your workflow file is ready, commit and push it:

git add .
git commit -m "Add GitHub Workflow"
git push origin main

Step 4: Verify the Workflow Execution

After pushing, go to your repository’s Actions tab on GitHub. Here, you can monitor the workflow execution and troubleshoot any issues.


Powered by Nextra