How to update a pull request from forked repo?
GitVersion ControlGithubGit Problem Overview
So I first forked a repo and then made a commit to that forked repo. I then opened a pull request. The pull request listed all the changes I wanted.
After reviewing my pull request, there were a number of changes that the repo owner wanted me to make before he accepted it. I have made those changes in my fork, now how do I update the pull request with those changes (or is this not how I should handle it)?
Git Solutions
Solution 1 - Git
You have done it correctly. The pull request will automatically update. The process is:
- Open pull request
- Commit changes based on feedback in your local repo
- Push to the relevant branch of your fork
The pull request will automatically add the new commits to the Commits
tab of the PR.
Solution 2 - Git
Updating a pull request in GitHub is as easy as committing the wanted changes into existing branch (that was used with pull request), but often it is also wanted to squash the changes into single commit:
git checkout yourbranch
git rebase -i origin/master
# Edit command names accordingly
pick 1fc6c95 My pull request
squash 6b2481b Hack hack - will be discarded
squash dd1475d Also discarded
git push -f origin yourbranch
...and now the pull request contains only one commit.
Related links about rebasing:
Solution 3 - Git
Just push to the branch that the pull request references. As long as the pull request is still open, it should get updated with any added commits automatically.
Solution 4 - Git
I did it using below steps:
git reset --hard <commit key of the pull request>
- Did my changes in code I wanted to do
git add
git commit --amend
git push -f origin <name of the remote branch of pull request>
Solution 5 - Git
If using GitHub on Windows:
- Make changes locally.
- Open GitHub, switch to local repositories, double click repository.
- Switch the branch(near top of window) to the branch that you created the pull request from(i.e. the branch on your fork side of the compare)
- Should see option to enter commit comment on right and commit changes to your local repo.
- Click sync on top, which among other things, pushes your commit from local to your remote fork on GitHub.
- The pull request will be updated automatically with the additional commits. This is because the pulled request represents a diff with your fork's branch. If you go to the pull request page(the one where you and others can comment on your pull request) then the Commits tab should have your additional commit(s).
This is why, before you start making changes of your own, that you should create a branch for each set of changes you plan to put into a pull request. That way, once you make the pull request, you can then make another branch and continue work on some other task/feature/bugfix without affecting the previous pull request.