54

I accidentally created a pull request from the master-branch of my fork of a repo.

While trying to rebase it I noticed that all of these changes were pushed into that pull request — due to the fact that you can simply Add more commits by pushing to the master branch on username/repo

  • Can you change the source branch of a pull request after the pull request has been submitted?

I see you can edit the base branch, but that's obviously not what I'm after.

1
  • More correctly, any changes to the target branch of a PR are automatically included in the PR. Commented Feb 22, 2017 at 7:09

3 Answers 3

43

AFAIK, you cannot change the source branch after creating a Pull Request. You have to create a new one instead.

For future reference, the established best practice is to create a new branch before making any commits. You should not commit directly to master, especially when contributing to team projects.

Side note:

you can simply Add more commits by pushing to the master branch on username/repo

More correctly, any changes to the target branch of a PR are automatically included in the PR.

Sign up to request clarification or add additional context in comments.

6 Comments

You can change the base branch after a creating a pull request. You just have to used the edit button
@TheGeorgeous as far as I can see you can only change the destination branch not source
base branch = target branch (thats always a bit confusing), thats the one you can change. Unfortunately not the source branch ( != base branch)
@Asara I don't understand your comment. Are you suggesting that I edit my answer? What changes are you suggesting?
@Code-Apprentice it was just a clarification, because different terms where used in the comments here and they are sometimes misleading no-advanced users.
|
9

Since you can't change the source branch in github (you can only change the target branch), you need to update the source-branch "inplace".

This answer contains three ways of doing this.

In Github you see:

githubuser wants to merge N commit into master from "source-branch"

Since you will change the history of "source-branch", be sure nobody else is using this branch!


Rewrite history of source-branch

If you are the only one developing on this branch, then you can use git rebase -i and later git push --force-with-lease.

This way you can rewrite the history of this branch.

Docs about rewriting the git history: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History


Rename temporary branch to source-branch

If you prefer to start from scratch.

git checkout master # create a temporary branch git checkout -b tmp-branch ... now modify the tmp-branch the way you want to. Commit, but don't push. # rename tmp-branch to "source-branch" git branch -f -m source-branch # Be sure nobody is using "source-branch", since the history gets rewritten. git push --force-with-lease 

git rebase --onto

Imagine your branch "source-branch" was accidentely based on "release" and not on "master". But the github target branch is "master". This way you can change your changes to be on top of master:

git checkout source-pr git rebase --onto master release 

2 Comments

That doesn't really solve anything if the source branch was set to master.
I followed the "Rename temporary branch to source-branch" approach.
-25

Screenshot 1Screenshot2

Yes we can edit the base branch/source after creating the pull request in the right hand side you get edit option see screenshot 1 attached, click on that and then you will be able to change base/source branch refer more on screenshot 2 attached with this comment

4 Comments

As you see in your screenshot you can change just the BASE branch.
'source' branch means which branch you want to merge into the base branch (or 'target' or 'destination' branch) And github won't allow you to change that.
I don't mean any harm but I suggest deleting this answer.
Funny but even though it's not the answer to this question, it was exactly what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.