Reputation: 963
I made a PR a couple days ago on github, but I accidentally made my changes on the master branch of my fork. Now I can't submit other pull requests because the master branch I have is modified and not in sync with the original projects master branch.
How could it be possible I can move the branch of the PR I made so I can continue creating new branches based off master, and submit new PR requests simultaneously?
Upvotes: 3
Views: 885
Reputation: 141622
Let's assume that you forked jQuery from [email protected]:jquery/jquery.git
, that you made two commits on your master branch, and that you opened a PR from master.
This would be the current state of affairs.
$ git log --oneline --graph --decorate --all -5
* abcd123 (HEAD -> master, origin/master, origin/HEAD) Your commit two
* abcd123 Your commit one
* abcd123 Some jQuery commit
* abcd123 Some jQuery commit
* abcd123 Some jQuery commit
Here is an approach to changing the PR to another branch.
First, create a new branch off of your master.
$ git checkout master
$ git checkout -b my-topic-branch
$ git push --set-upstream origin my-topic-branch
Second, add the original repository as a new remote called upstream.
$ git remote add upstream [email protected]:jquery/jquery.git
Third, rollback your master to the upstream master.
$ git fetch upstream
$ git checkout master
$ git reset --hard upstream/master
$ git push --force-with-lease
Finally, delete the PR that you created off of master
, and create a new PR off of my-topic-branch
.
This would be the final state of affairs.
$ git log --oneline --graph --decorate --all -5
* abcd123 (origin/my-topic-branch, my-topic-branch) Your commit two
* abcd123 Your commit one
* abcd123 (HEAD -> master, upstream/master, origin/master, origin/HEAD) Some jQuery commit
* abcd123 Some jQuery commit
* abcd123 Some jQuery commit
Upvotes: 1