4

I have a github repo that has master and a branch. We have been developing on branch and then every time we push out a release, we merge the branch's changes into master, then start the next phase of development on branch again. Now, we are asked to use pull request for bug fixes on branch. So the question is, how to do all of the pull request on the branch alone, not involving the master?

More specifically, I have branchA that has a bugfix change, then I commit and push to the branchA repo, then I go to my github repo webpage and try to do a pull request by specifying both the base branch and the compare branch as 'branchA', then github says: There isn’t anything to compare. You’ll need to use two different branch names to get a valid comparison. This definitely makes sense, so I am asking if it is possible to somehow compare the SAME branch before and after bug fix via a pull request.

Gino Mempin
  • 12,644
  • 19
  • 50
  • 69
For Comment
  • 700
  • 3
  • 10
  • 18
  • Are you using a remote git hosting service? E.g. github, bitbucket or gitlabs? – k0pernikus Aug 18 '17 at 23:56
  • sorry, it is github – For Comment Aug 19 '17 at 01:10
  • You said you pushed to branchA-if you want to make a PR into branchA then you need to branch off of branchA and create a PR from that into branchA. If you just push to branchA there's nothing to create a PR from. – Dave Newton Aug 19 '17 at 15:38
  • @DaveNewton so, is it possible to do the PR before push, somehow? – For Comment Aug 19 '17 at 16:52
  • ... I think you're misunderstanding the expected workflow. Let's say I want to do something on `branch-a` but not modify it directly, e.g., create a PR against `branch-a`. I create a new branch, call it `branch-a-fix`. I push up `branch-a-fix`. I create a PR from `branch-a-fix` into `branch-a`. The PR is reviewed and eventually merged (for the sake of argument). Now `branch-a` contains the fix. Eventually you may create a PR from `branch-a` into `master`. – Dave Newton Aug 19 '17 at 18:01
  • @DaveNewton I agree with the approach that you described here, which is way that I have been doing. So, I'll wait a bit to see if others will help confirm that there is no other way, then you can post this comment as a solution, then I will accepted it. – For Comment Aug 20 '17 at 08:45
  • I don't understand. You already know this? What are you even asking then? How to create a PR without making a branch? – Dave Newton Aug 20 '17 at 12:00
  • @DaveNewton Well, yes, because I actually had a pull request directed at me from a different owner of the github repo that was done on the same branch (not a separate branch), so I am mystified, that's why I am asking as I myself couldn't find out how that was done. – For Comment Aug 21 '17 at 07:53
  • @ForComment Ask them? – Dave Newton Aug 21 '17 at 13:12
  • @DaveNewton I have, but got no response, when I can verify how that's done, I'll post that as an answer, perhaps, but based on all the threads here, it doesn't seems possible... – For Comment Aug 22 '17 at 18:12
  • @DaveNewton Ok, I got response that says that PR was coming from a fork of the repo, so that's why it appeared to be on the **SAME** branch, but actually it was from a different repo, technically. Not sure I should post this as the answer... – For Comment Aug 22 '17 at 20:02
  • @ForComment Might as well' might save someone some confusion some day. – Dave Newton Aug 22 '17 at 22:28

4 Answers4

7

The phrases "do all of the pull request on the branch alone" and "not involving master" does not really make sense, because a pull request is basically a set of changes that are requested to be merged into a branch, which in your case would be the master branch.

Here is a description from GitHub's page on pull requests:

Pull requests let you tell others about changes you've pushed to a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before the changes are merged into the repository.
...
After initializing a pull request, you'll see a review page that shows a high-level overview of the changes between your branch (the compare branch) and the repository's base branch.

In addition, creating a pull request will require you to specify the branch you want to merge the changes into, which in your case, would be the master branch.

If you're intent on never involving the master branch, you can create a patch instead for the commits relating to the bug fixes, then perform the code review there. (You can also create a patch by diff-ing the modified files). But that will just make code review more difficult.

Gino Mempin
  • 12,644
  • 19
  • 50
  • 69
  • PRs can go against any branch, which may or may not involve master in the branch's lifetime. They often do. Your first quote says nothing about branches, only the repo, which consists of all branches. For example, there may be a long-lived branch that lives in parallel with master, into which master is merged, but never the inverse. – Dave Newton Aug 19 '17 at 14:51
  • @DaveNewton, I updated my original post to be more specific describing my question, please take a look, thanks. – For Comment Aug 19 '17 at 15:16
  • @DaveNewton You are right. I was working on the OP's use case that there are only 2 branches, `master` and `branch`. I edited my answer to clarify that. – Gino Mempin Aug 19 '17 at 15:24
6

If the PR will be issued from the same github repo, then it has to be done via branching, i.e. create a branch off of a known branch and make changes, then create PR by comparing the two branches. Thanks to everyone who helped confirm this.

If someone makes a fork of a github repo, then changes in the forked repo can be used to issue PR based on seemingly same branch (in two different repos, i.e. one original, the other the fork). This is where I was confused because I saw the PR came from seemingly the same branch, but actually, it is from a different repo (a fork), technically.

For Comment
  • 700
  • 3
  • 10
  • 18
3

Pull requests are simply tell github that i want this branch to take this commits only after it has been reviewed and approved.

When doing a pull request, it involves two branches 1. The comparing branch (The one you're pushing) 2. The base branch (The one to review changes after approval)

The base branch is usually master, but not limited to master.

Simply change it to the branch you want to merge the PR into and you're done!

Pull requests is not meant for master alone!

Subomi
  • 280
  • 2
  • 14
0

As you mentioned, you did your development to a (topic) branch and then merge it to master. Ideally, this also is a subject for using pull request (PR).

Think of PR as a request to merge branchA(topi/development/bugfix) to branchB(master). Why not merge directly like you did before? To let other developers review the code before merging it to stable branchehs or to utlize CI/CD servers.

letthefireflieslive
  • 6,782
  • 6
  • 21
  • 45
  • I am asking if PR as a request to merge branchA(bugfix) to branchA(the same branchA before the bugfix) is possible? I tried and it doesn't seems possible, so is it? – For Comment Aug 19 '17 at 14:48
  • @ForComment It is most definitely possible, and common. When you open the PR you can specify which branch it targets. – Dave Newton Aug 19 '17 at 14:52
  • @DaveNewton I've updated my original post to be more specific about my question, please take a look, thanks. – For Comment Aug 19 '17 at 15:19
  • 1
    @ForComment within the same branch, I think you can't. Branch creation is cheap, just create one and PR it. https://stackoverflow.com/questions/34027850/how-to-pull-request-a-specific-commit – letthefireflieslive Aug 20 '17 at 11:27