Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update GitHub forked repo when a pull request was denied?

I forked a repo on GitHub and submitted a pull request. The maintainers of the project rejected the pull request, but we worked out a better solution in a forum. They instructed me to create another pull request with the alternative changes. However, my fork of the repository on GitHub is now out-of-date, as updates have been pushed to the main repo since I forked. Also, the repository on GitHub has an extra commit (my pull request commit) that shouldn't be there, because it was not accepted as part of the project.

I found this question: How do I update a GitHub forked repository?

I followed the instructions, specifically, I did this:

git remote add upstream git://github.com/fuel/core
git fetch upstream

That resulted in:

remote: Counting objects: 93, done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 69 (delta 49), reused 40 (delta 20)
Unpacking objects: 100% (69/69), done.
From git://github.com/fuel/core
 * [new branch]      1.0/master -> upstream/1.0/master
 * [new branch]      1.1/master -> upstream/1.1/master
 * [new branch]      1.2/develop -> upstream/1.2/develop
 * [new branch]      1.2/master -> upstream/1.2/master
 * [new branch]      1.3/develop -> upstream/1.3/develop
 * [new branch]      1.3/master -> upstream/1.3/master
 * [new branch]      1.4/develop -> upstream/1.4/develop
 * [new branch]      1.4/master -> upstream/1.4/master
 * [new branch]      1.5/develop -> upstream/1.5/develop
 * [new branch]      1.5/master -> upstream/1.5/master
 * [new branch]      1.6/develop -> upstream/1.6/develop
 * [new branch]      feature/better-hmvc -> upstream/feature/better-hmvc

Okay, so that seems all fine and good. I made sure that I was on the correct branch:

git checkout 1.6/develop
Already on '1.6/develop'

Word. Okay, now for this:

git rebase upstream/1.6/develop
First, rewinding head to replay your work on top of it...
Applying: prevent invalid XML node names

Wait...what? Why is "prevent invalid XML node names" being applied? That is the pull request that was rejected by the project maintainers. I'm obviously missing the boat on the real meaning of "rebase." Now if I git status it says:

# On branch 1.6/develop
nothing to commit (working directory clean)

When I git log, I can see that half of my problem has been resolved. The changes that have been pulled into the project since I forked are now reflected in my git log. However, the most recent commit remains "prevent invalid XML node names". How do I obliterate it?

I tried checking out the last commit made to the project:

git checkout 5f31a4df55e5b6ca1b2092534063a1fce4a32181

However, this leaves me in a detached HEAD state. It says I can look around, make changes and commit them. I don't think that's what I want to do. I think I want HEAD to point to commit 5f31a4df55e5b6ca1b2092534063a1fce4a32181. What is my next step?

like image 956
Ben Harold Avatar asked May 03 '13 17:05

Ben Harold


People also ask

How do you update a pull request from forked repository?

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.

How do I update my forked repository in GitHub?

On GitHub, navigate to the main page of the forked repository that you want to sync with the upstream repository. Select the Sync fork dropdown. Review the details about the commits from the upstream repository, then click Update branch.

Does forked repo automatically update?

2. The new API. Next method I have for you to synchronize your forked repo with the upstream one requires a little more setup, but then it will allow you to keep the repos in sync automatically.


2 Answers

git rebase will keep your commit on your branch. As your PR been rejected, you want to delete it and make your master branch the same as upstream/master.

As so, you want to reset!

git checkout master
git reset --hard upstream/master

Then you'll have the exact same master as the upstream one. Then, create a new branch for your new PR, so you won't have this problem again.

like image 72
Simon Boudrias Avatar answered Oct 05 '22 03:10

Simon Boudrias


As this question has a already accepted answer but I am going to tell you another way because accepted answer did not went well in my case.

Executing

$git rebase    
There is no tracking information....

$git checkout
Already on 'master'

$git reset --hard upstream/master
ambiguous argument upstream/master

If such situation arises then please go through these steps.

Locally reset HEAD.

$git reset HEAD

make same changes on server repo.

$git reset HEAD^

Then it will show the message about changes that you made to original forked repo of yours, listing all the files. Unstaged changed with file names.

Now undo your changes using:

$git stash

Now you can force push these changes to Sever to point your local and remote repo on same HEAD.

$git push origin +HEAD

Now you are at the same repo where you were at the time of fork. Now you can pull again for latest code from original repo.

like image 39
Master Avatar answered Oct 05 '22 03:10

Master