I am not the best Git user, and am having an issue whenever I create a PR. Basically, when I make a PR, I am shown a large list of all my previous commits including the one that I just committed (the one I want merged to Master branch). The flow that I do is the following:
First I fork a copy of our Master branch, and
git clone [local copy]
Then I create a remote
git remote add upstream [main repo url]
Then every time I have made changes I want to add to my PR:
git add [file1] [file2 ] ...ect
Then commit:
git commit -m 'blah blah blah'
And finally push to origin:
git push origin master
After this, I create a PR on Github, where it shows all the previous commits. Is there a way to not list all of these and only show my latest commit? It shows commits that were merged to the upstream long back and are in sync with it. It would be nice for the merger to not have to select the specific commits and just the ones listed.
Thanks!
Your workflow does not seem right. There are two options how you can contribute:
You have write permission in the upstream repository. Then You should simply clone the upstream repository, checkout a new branch git checkout -b fix/my-fix
and commit your changes there. Once you are done, you push your new branch to upstream git push origin fix/my-fix
and open a PR inside that repo.
You don't have write permissions, i.e. you can't push any branches to the upstream repo. First you have to create a private fork of the repository, then clone your fork to your computer. Also now you should create a new branch for your fix or feature addition. Once you have that, you push the branch to your private repo. This part is a bit confusing, but github will make it work. You can then open a PR in the original upstream repo from within your forked repo. For that, navigate to your github profile and your repository and start a PR with your new branch. You should be able to chose the upstream master as the merge target for your new branch.
If you still see all the old commits when you open a new PR, then your branches have diverged, someone force pushed changes to master or something like that. You can check the common ancestor of two branches branch_1
and branch_2
with git merge-base branch_1 branch_2
. Then you can use interactive rebase git rebase-i
to put your branch on top of another one and drop all unnecessary commits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With