Git workflow for pre-commit merge?

67 Views Asked by At

Using SVN, the workflow I followed in order to ensure that I didn't break the build was:

  • Do work
  • svn update to get latest commits from others into my wc
  • Recompile, run tests, fix any issues (e.g., reliance on API that I am changing)
  • svn commit

When I try to replicate this workflow in Git, I get the dreaded "Your local changes to the following files would be overwritten by merge" error.

What are the steps to merge origin changes into my local copy so I can validate before committing? Is there a way to specify to merge each file and edit conflicts like in SVN?

2

There are 2 best solutions below

1
On BEST ANSWER

One difference between Git and SVN is that Git splits the "record my changes to the code" step into two steps: a commit, and a push, whereas SVN just has a commit. In Git, the resolution of conflicts happens after the commit, but before the push. This means that the process seems almost "opposite" to SVN, where you update, then resolve conflicts, then commit. In Git, you want to instead commit, then pull (at which point you may resolve conflicts), then push.

0
On

Why don't you try this?

git add somefile
git commit -m "this will save my local changes"

git pull origin master
#this merges with origin master, if there's a merge error. You can fix it
# and commit again

git push origin master 
#this will push the merge with the remote master