GitHub pull requests

Estimated time to read: 3 minutes

Find a simple guide with the process of setting up Git on your laptop, using GitHub Pull Requests, and protecting your GitHub repo by allowing changes through pull requests only.

Setting up Git on your laptop:

  1. Download and install Git:

  2. For macOS: Install Git using Homebrew (https://brew.sh) by running brew install git in the terminal.

  3. Configure Git: Open a terminal (Command Prompt or Git Bash on Windows) and configure your name and email address, which will be used for your commits:

Bash
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Protecting your GitHub repo with pull requests only:

To ensure that changes can only be made through pull requests, you can enable branch protection rules for your repository:

  1. Go to the "Settings" tab of your repository on GitHub.

  2. In the left sidebar, click "Branches".

  3. Under "Branch protection rules", click "Add rule".

  4. In the "Branch name pattern" field, enter the name of the branch you want to protect (e.g., "main" ).

  5. Check the "Require pull request reviews before merging" option. You can also configure additional options, such as requiring a specific number of approving reviews or dismissing stale reviews when new commits are pushed.

  6. Click "Create" to save the branch protection rule.

With these branch protection rules in place, direct pushes to the protected branch will be restricted, and changes can only be made through pull requests that have been reviewed and approved according to your specified criteria.

Using GitHub Pull Requests:

  1. Create a GitHub account if you don't have one (https://github.com).

  2. Fork the repository you want to contribute to by clicking the "Fork" button on the top right corner of the repository page.

  3. Clone the forked repository to your local machine:

    Bash
    git clone https://github.com/YOUR_USERNAME/REPOSITORY.git
    
    Replace YOUR_USERNAME and REPOSITORY with your GitHub username and the repository name, respectively.

  4. Add the original repository as a remote to sync your fork with the upstream repository:

    Bash
    git remote add upstream https://github.com/ORIGINAL_OWNER/REPOSITORY.git
    
    Replace ORIGINAL_OWNER and REPOSITORY with the original owner's GitHub username and the repository name, respectively.

  5. Create a new branch for your changes:

    Bash
    git checkout -b your-feature-branch
    
    Replace your-feature-branch with a descriptive name for your branch.

  6. Make your changes, add them to the staging area, and commit them:

    Bash
    git add .
    git commit -m "Your commit message"
    

  7. Push your changes to your fork on GitHub:

    Bash
    git push origin your-feature-branch
    

  8. Go to the GitHub page of the original repository, and you should see a message suggesting to create a pull request with your changes. Click the "Compare & pull request" button.

  9. Review your changes, add a descriptive title and comment explaining your changes, and click "Create pull request".