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:
- Go to GitHub (opens in a new tab) and log in.
- Click the + button in the top right and select New repository.
- Enter a repository name and description.
- Choose visibility (public or private).
- Initialize with a README (optional).
- 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)
- Navigate to the repository on GitHub.
- Click Pull requests > New pull request.
- Select the base and compare branches.
- Add a title and description.
- Click Create pull request.
Merging a Pull Request
- Go to the pull request on GitHub.
- Click Merge pull request.
- Confirm the merge.
- 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
- Navigate to the repository.
- Click Issues > New issue.
- Add a title, description, and relevant labels.
- Click Submit new issue.
Participating in Discussions
- Navigate to the Discussions tab of a repository.
- Click on an existing discussion or start a new one.
Using GitHub Actions
Setting Up a Workflow
- Go to the Actions tab in the repository.
- Select a pre-built workflow or create a new
.github/workflows/main.yml
file. - Define the workflow steps and triggers.
- 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.