Git: Merge to master while automatically choosing to overwrite master files with branch

To disregard master, when you have branch checked out then:

git merge master --strategy=ours

http://schacon.github.com/git/git-merge.html

As 'Computer Linguist' commented here, this will "ignore everything from 'master', even if it has changes to new, independent files". So if you are not the OP and want a more safe merge that does not as the OP says "forget the merging", then use this excellent safe command from 'Computer Linguist', and plus his comment up so he gets creds.

git merge -s recursive -X theirs branch

In version 1.7.1 of Git, you can use "-Xtheirs" to merge in the branch itself.

For example, if you start in your master branch, starting in master

git checkout -b editBranch
-- edit your files --
git add .
git commit -m "Updated the files"
git checkout master
git merge -Xtheirs editBranch

Another way that I've seen to do this based off this post is to do a hard reset off the editBranch. For example:

git checkout -b editBranch
-- edit your files --
git add .
git commit -m "Updated the files"
git checkout master
git reset --hard editBranch

I think this second way might be the better play, but I haven't had a chance to play around with it enough yet.


I believe you can do this with the 'ours' merge strategy:

git checkout branch
git merge -s ours master

But this doesn't do exactly what you want: it override the contents of the current working branch branch and what you want is to get the same contents onto master. What you really want is a merge strategy theirs, and for that I point you at this similar question for a way to do it. In practice what it boils down to is resetting master to point at branch.