Search code examples
gitgithubgit-mergegit-commit

Github commit conflict


In GitHub, I cloned version 1 of the repository and made changes in it. While I was making changes someone else also cloned the repository and made changes and committed the changes which are not on my local machine, now if I want to commit my changes then will their changes be retained or it will be overwritten by my code?

I want to merge both the codes such that changes of both of them are retained.


Solution

  • Your changes won't override the other changes. There are 2 recommended ways to handle your case:

    1. If your changes are in other files than the other changes just push and open a PR for your changes. It will merge the changes without problems.

    2. If the changes are in the same files there's a risk of merge conflicts, that git can't automatically figure out what code to keep. In this case I suggest rebasing. This will make your changes go after the other changes.

    2.1. git checkout main to use your local main branch

    2.2. git pull to get the changes from origin into your local main branch

    2.3. git checkout your_branch to use your branch

    2.4. git rebase main to take your changes and move them to after the change. This might cause conflicts, if it does just follow the instructions to solve them.