How do I resolve a conflict in git when uploading to github?

2

These are the steps I took:

git clone "https://github.com/dixroby/codigoNuevo"

Then I generated a conflict by editing a line of code and when uploading

git add . 
git commit -m "subiendo conflicto"
git push

I get an error error: failed to push some refs to 'https://github.com/dixroby/codigoNuevo.git'

then I do a

git pull

and again a

git push

and the problem is solved

The question is, are the steps I show correct? As far as I know, I have to solve that conflict by choosing the original or the new modification.

  

Is it the correct way to solve a conflict?

    
asked by Dixroby Arone Cuellar 27.10.2018 в 17:20
source

1 answer

2

A git push can only fail if someone has modified the copy in Githhub before your push (either because you have edited "online" something, or because you have done a push, before yours) . In that the push is rejected because your local copy of the repository is not updated. It is not really a conflict yet, but a mere warning that you are not up to date.

You must do a pull to update it. At that moment a conflict can be generated if what you download with pull "collides" with the local changes (you have locally modified a file that was also modified in the push). But there may also be no conflict (because remote changes do not collide with local changes), in which case git will simply mix both changes creating a new commit with the mix.

If there are conflicts instead, Git can not complete the mix without your help. You must solve the conflict by looking at the files that have "crashed" and leaving them to your liking.

Git will have introduced in these files some marks of the style <<<<<< and >>>>>> to delimit the lines in conflict. Between both marks a line of ====== will appear to separate the version you had locally from the remote version.

You must read those lines carefully, decide on one of the two versions (or make a mix yourself and create a new one) and eliminate all those marks. That is, you must leave that file as you would like it to be in its final version.

Once done, you will do a git add of that file and git commit to complete the pull that had been "interrupted" by the conflict. That will create a new local commit that saves the changes you made during the mix.

Whether there was a conflict or not, once the pull is completed it is convenient that you make a git push so that the remote repository also contains the commit "mix" (plus the local commits that were not yet in the remote one) ).

    
answered by 27.10.2018 / 17:36
source