![git create branch from another branch git create branch from another branch](https://tortoisegit.org/docs/tortoisegit/images/SwitchCheckOut.png)
And it will still look exactly the way you want. If feature1 is now accepted and merged, the PR will automatically change to a merge into main, which is what you wanted all along. It will look just the way you want! - And here is the wonderful part. Sounds bad, eh? But no problem! Just push feature2 anyway, and ask for a PR merging into feature1. With this, you fetch all the branches in the repository, checkout to the one you specified, and the specific branch becomes the configured local branch for git push and git pull.
git clone -bIn that case, pull main and rebase feature2 onto main, and push feature2 and ask for a PR merging into main. In the meantime, feature1 PR got approved and merged. Then you want to keep working, so you make a branch feature2 off of feature1, and when you finish, there are two possibilities: So from main you make a branch feature1 and push it and ask for a PR merging into main. For aliases, you have two choices, you can either create a git alias or a bash alias. So let's say you work on feature branches off of main. In order to avoid having to define the upstream everytime you create a new branch, define an alias for the command we just wrote. You just have to make sure the second PR doesn't get accepted before the first. I welcome any comments on a better workflow as well.Īctually, GitHub copes perfectly well with this situation.
![git create branch from another branch git create branch from another branch](https://i.stack.imgur.com/qp7BB.png)
#GIT CREATE BRANCH FROM ANOTHER BRANCH UPDATE#
I just want the second PR to look like it is committing changes into the first PR.Īfter the first PR is merged, I then usually go into the second branch and rebase -onto our_main_branch and update the second PR in github to request merging changes into our_main_branch. Is there a way to prevent this problem from happening? I never want the first PR's changes to appear in the second PR (as commits). I try this weird thing where I change the branch in the second PR to some other common ancestor branch, and then change it back to the first branch, and suddenly the changes from the first branch that shouldn't have appeared disappear. It's a linear history and I think github is confused. However, the problem is that the second PR sometimes shows changes from the first branch. I then force push the first branch and second branch to their remotes. Meanwhile, if I have changes for the first branch (addressing the first PR's comments), I commit them into the first branch, and then rebase them into the second branch. To do that, I first create another branch (off of the earlier branch) and open a PR that requests changes into the first branch. I want reviews on the second PR while the first PR is still open. However, sometimes I want to create another PR that depends on the PR from earlier that is still open. I usually create a branch and open a pull request on github (standard procedure). If you haven't, no problem.I have a workflow that needs some assistance. The force push will only be required if you've already pushed branch_b to origin. This will give you a fresh branch_b from master, where the commits from A now exist, and you won't have merge conflicts when you merge B into master. # Exclude (skip or comment out) the commits that were from A, leaving only B Once you have merged A into master, you will probably need to rebase branch_b onto the new master, and get rid of all of the original commits you took over from branch_a, since they all now exist in master: # Assume A merged into master Given that branch_b's tests presumably depend on branch_a it would seem silly to merge B before A. If you want to take branch_a commits with you, then you can merge branch_b into master at any time, although that sort of voids the purpose. Can I merge Branch 'B' independent of Branch 'A'? No, they're entirely separate branches so only the commits from branch_a will exist in master. Once I merge Branch 'A' to master, will that also include Branch 'B' even though i'm not done yet? You'll then have the commits from branch_a in your new branch_b. How can I do this in git? git checkout branch_a