I wanted to know how I can unify branches from a remote repository.
I made an application to know the weather and when I wanted to upload it, in the remote repository the base was created in the main branch (that by GitHub). Then I added the rest of the project and did the commit and push through GitBash.
When I see the repository, I see that everything was pushed to a "master" branch, and I have searched various places and tried forms for hours but I have not been able to merge them, I would like to know how to do it or at least some idea so I can solve it. I want to leave everything in the main branch. From already thank you very much.
If the branches were left without a common ancestor, since it is a new project, I would mount what you did in
master
envelopemain
(which is the branch that has the remote repository). Assuming it's origin:And ready.
My suggestion is to leave everything in "main", but if you really care about names, do this:
git switch -c main
, to switch to the local "main" branchgit pull origin main
, to pull changes from the remote "main" branch, but to your local repository. Here you can have conflicts and you must resolve them before committinggit switch master
, and we return to the local branch "master"git rebase -i main
, and with this, from master , we can interactively apply the commits made in master and main. We can also mix or rename commits. "p" or "pick", tells git to apply the commits; "s", or "squash", which applies the commit but mixes it with the commit above (only the first commit cannot be squashed). But leaving everything as it is in the file, and closing it, it should begit add
to the files, and continue withgit rebase --continue
. If we don't like it, we givegit rebase --abort
to leave everything before the rebasegit push -f origin master
, so that local changes are pushed to the remote branchIn short, the remote has to be made to reflect what happened locally. That is, you download all the remote changes, you operate locally, and then everything you operated locally, you make remote.