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.
-
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.
-
Clone Your Fork:
git clone https://github.com/your-username/repository-name.git cd repository-name
-
Create a New Branch:
git checkout -b your-branch-name
-
Make Your Changes:
- Edit the files using your preferred text editor. For example, if you use
vi
:vi filename
- Edit the files using your preferred text editor. For example, if you use
-
Add the Changes:
git add filename
-
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 <[email protected]>
- Save and close
vi
:- Press
Esc
to exit insert mode. - Type
:wq
and pressEnter
to save and quit.
- Press
- Open
-
Push Your Changes to Your Fork:
git push origin your-branch-name
-
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.
-
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
- To keep your fork up-to-date with the upstream repository:
-
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.
- Make the Requested Changes:
- Edit the files as needed using your preferred text editor. For example, if you use
vi
:
vi filename
- Add the Changes:
git add filename
- 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 <[email protected]>
-
Save and close
vi
: -
Press
Esc
to exit insert mode. -
Type
:wq
and pressEnter
to save and quit.
- 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
-
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.