Skip to content

Instantly share code, notes, and snippets.

@nerdalert
Created June 14, 2024 19:42
Show Gist options
  • Save nerdalert/b67a6eefd0056478ef46bb901cd9156a to your computer and use it in GitHub Desktop.
Save nerdalert/b67a6eefd0056478ef46bb901cd9156a to your computer and use it in GitHub Desktop.

Here are the steps to open a PR (Pull Request) to a GitHub repository, including how to commit messages with vi and DCO (Developer Certificate of Origin) signoff.

Step-by-Step Guide

  1. Fork the Repository:

    • Go to the GitHub repository you want to contribute to.
    • Click the "Fork" button at the top right of the repository page.
    • This creates a copy of the repository under your GitHub account.
  2. Clone Your Fork:

    git clone https://github.com/your-username/repository-name.git
    cd repository-name
  3. Create a New Branch:

    git checkout -b your-branch-name
  4. Make Your Changes:

    • Edit the files using your preferred text editor. For example, if you use vi:
      vi filename
  5. Add the Changes:

    git add filename
  6. Commit Your Changes with DCO Signoff:

    • Open vi for the commit message:
      git commit -s
    • Write your commit message. For example:
      Add feature X
      
      This commit adds feature X to the project, which allows users to do Y.
      
      Signed-off-by: Your Name <your-email@example.com>
      
    • Save and close vi:
      • Press Esc to exit insert mode.
      • Type :wq and press Enter to save and quit.
  7. Push Your Changes to Your Fork:

    git push origin your-branch-name
  8. Open a Pull Request:

    • Go to your forked repository on GitHub.
    • You will see a "Compare & pull request" button. Click it.
    • Fill in the details of your PR, including the title and description.
    • Submit the PR.

Additional Tips

  • Sync with Upstream Repository:

    • To keep your fork up-to-date with the upstream repository:
      git remote add upstream https://github.com/original-owner/repository-name.git
      git fetch upstream
      git checkout main
      git merge upstream/main
      git push origin main
    • If you are working on a branch, merge the updates into your branch:
      git checkout your-branch-name
      git merge main
  • Review Your PR:

    • Before submitting, review your changes and ensure they meet the project's contribution guidelines.
    • Check for any build or test failures.

By following these steps, you can contribute to open source projects on GitHub while ensuring your commits are properly signed off according to the Developer Certificate of Origin (DCO) requirements.

Step-by-Step Guide to Amend a Commit

  1. Make the Requested Changes:
  • Edit the files as needed using your preferred text editor. For example, if you use vi:
vi filename
  1. Add the Changes:
git add filename
  1. Amend the Last Commit:
  • Use git commit --amend to add the changes to the previous commit. This will open your default text editor (e.g., vi) for the commit message:
git commit --amend
  • Update the commit message if necessary. Ensure the Signed-off-by: line is included for DCO signoff. For example:

Fix issue with feature X

  

This commit fixes the issue with feature X by addressing Y.

  

Signed-off-by: Your Name <your-email@example.com>

  • Save and close vi:

  • Press Esc to exit insert mode.

  • Type :wq and press Enter to save and quit.

  1. Force Push the Amended Commit:
  • Since you have amended a commit that has already been pushed, you need to force push the changes to your branch:
git push --force origin your-branch-name

Additional Tips

  • Rebase for Multiple Commits:

  • If you need to amend a commit that is not the last one, you can use an interactive rebase:

git rebase -i HEAD~n

Replace n with the number of commits you want to rebase. This opens an interactive editor where you can mark the commit you want to amend with edit.

  • Make your changes, then:
git add filename

git commit --amend

git rebase --continue
  • Finally, force push your changes:
git push --force origin your-branch-name
  • Addressing Merge Conflicts:

  • If you encounter merge conflicts during a rebase, Git will pause and allow you to resolve them. After resolving conflicts, add the resolved files:

git add resolved-file

git rebase --continue

By following these steps, you can effectively amend commits in response to reviewer feedback and ensure your changes are properly integrated into the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment