I have just now started using Git and previously used CVS for versioning.
Can someone explain me how to deal with merge conflict cases in Git? Also what is the standard procedure to follow in such cases.
I faced a situation after doing the below steps,
- I had committed some files into my local repository using
git addandgit commit - Later when I tried to push my local repo changes to a remote repo, it fails with a non-fast-forward error and prompts me to pull before pushing.
- So I tried
git pullto fetch the latest from remote repo into my local repo. Pull failed and said there were merge conflicts.
Let’s assume I pull from the remote into my local repo and then do step 1 (committing files). What happens if someone else pushed their changes before I push to the remote repo. I believe push ending with merge is a usual case. How to deal with these cases?
I assume pull involves fetch + merge. In my case automatic merge seems to have failed. What do I have to do in the above case? Please also tell me how to avoid getting into such situations?
Here’s a quick list of how I do my git commits:
git clone <repository url>git stash: this stashes your uncommitted changes away in a temporary cache (and temporarily removes them from the working directory, so you have a clean copy)git pullto get latest repository versiongit stash popapplies stashed changes to local repository (and remove them from the stash); this might produce conflicts, just like a merge or rebasegit add <changed files>git commit, using-mto provide a short message or leaving it out to open an editorgit pushto publish your changes to the remoteThey way to avoid the problem you hit is to stash your changes before a pull, then pop the stash after pull is complete.