13

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?

Community
  • 1
  • 1
Ben Harold
  • 6,242
  • 6
  • 47
  • 71

2 Answers2

9

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.

Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
  • 3
    Thanks! I'd like to repeat for emphasis, because it was so helpful to me: **"Then, create a new branch for your new PR, so you won't have this problem again."** – Ben Harold Jun 19 '13 at 20:47
  • This seems to be a bit more precise: http://stackoverflow.com/a/8135023/89818 The push was necessary for me. – caw Feb 23 '14 at 06:38
1

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.

Master
  • 2,945
  • 5
  • 34
  • 65