Basically I was working on my branch, made some changes to the existing files. I want to make a pull request. However, there has been some changes in main, so I think I probably need to rebase my branch with main first. In this case, if I rebase with main, will it delete my code changes in my own branch? Sorry maybe I sound ignorant but I am totally new to this. Please provide me with the workflow I need to follow so I can make sure my branch is up to date with the main branch without deleting any of my changes and make a pull request.
Asked
Active
Viewed 1,182 times
-1
-
I think your question really boils down to *how does rebase work*, for which there are a lot of answers that will eventually get you there: [When do you use Git rebase instead of Git merge?](https://stackoverflow.com/q/804115/1256452) compares merge vs rebase, and [Git conflicts in rebase vs merge](https://stackoverflow.com/q/66090607/1256452) has one of my tutorial-answers. But if that's not really what you mean to ask, you might need to reformulate your question. – torek Jan 25 '22 at 07:02
1 Answers
0
If you have not pushed any of your changes, then you can indeed rebase with git rebase main
and you will not lose any of your changes; those changes will be "replayed" onto the latest commit of the main
branch. If you have pushed any of your changes, however, you are better off doing a git merge main
instead. The reason for this is that if you rebase commits that have already been pushed, you will get duplicates of those commits.

David Deutsch
- 17,443
- 4
- 47
- 54