What I have done
In local repo:
git checkout -b feature/db/projectImport dev- make changes
git add .andgit commitgit push origin feature/db/projectImport(staying in that branch)
Now in GitHub:
5. Click the Compare & pull request button and finally merge with the default merge button, which claim to use --no-ff
What I want to achieve
- I don't want the commits messages from the feature branch to appear in the commit messages in the dev branch.
- When I merge the
featurebranch intodev, the feature branch will retain all its commits but thedevbranch will only have the merge commit. Is this possible???
Related Images from the repo
Feature branch commits:
Dev branch commits:

Note:
- I am newbie in
git. So, my thinking can be wrong. If this is the case, please point out my mistake and tell what is correct. - Any suggestion gratefully received. Thanks in advance.
CodePudding user response:
As others have pointed out in the comments, what you are looking for is the squash option when you merge the PR in.
When you squash-merge, that changes what appears on the destination branch, but it does not change what is on the source branch. So on dev, you'll see one commit. But on the feature branch, as long as you don't delete it, you'll continue to see all your original feature commits. And the PR will continue to hold a pointer to that branch.
Now, that's a bit of a funny workflow to me: when I merge a PR in, I systematically delete the feature branch. But your workflow should work fine too.
How to do it
On GitHub
Once you have your PR ready to merge, make sure you merge it in using GitHub's "squash and merge" method:
On the Git CLI
If you're doing the merge on your own computer, the same operation can be accomplished like this:
git checkout dev
git merge --squash feature/feature-name
git push origin dev
The results
With either method, you will get to write a new message for the squashed commit that will get added to dev.
Once you've completed the merge, dev will have one new commit, and branch feature/feature-name will remain unmodified.


