Git Merge: Accept All Changes

Have you encountered a large merge when you know you are going to accept all current or incoming changes? There's a way to achieve without stepping through each file.

I ran into a scenario recently in which I had about 100 merge conflicts. It was going to be a daunting (and tedious) task. When that happens to me, I spend a little time brainstorming if there is a better way. To my surprise, this was as cool and relaxing as a walk in a park.

In this case, I knew I wanted to accept all current changes. In other words, I knew that all the files I had were the most updated versions of the files and could safely ignore any incoming changes.

The first step is to back out of the current merge or stash any active changes. If you don't have any active changes or aren't in the middle of a merge, you can ignore this step.

$ git add .
$ git stash

If stash doesn't work or you don't want to muddy your stash list, you can also reset. Use this command with caution, as it is destructive:

$ git reset --hard

Then, restart the merge using a strategy option. In my case, I wanted to accept all current changes and ignore any incoming changes, which I could accomplish like this:

$ git merge [branch] --strategy-option ours

[branch] should be replaced with the name of the branch you are merging into your current branch.

If, instead, you know you want to overwrite any current changes and accept all conflicts from incoming changes, you can use the theirs strategy instead:

$ git merge [branch] --strategy-option theirs

Once that's done, if you had stashed files, you can bring them back to life:

$ git stash pop

Let's Connect

Keep Reading

Backup Gitlab Data and Repositories to Amazon S3

Make sure you don't lose all that precious GitLab data by backing regularly and syncing with an Amazon S3 bucket.

Dec 11, 2014

Collaborate On A GitHub Gist

GitHub gists are designed to be user-specific and not for team collaboration. But you can make it work with a little finagling.

Apr 25, 2018

Free Alternatives to GitHub for Private Git Hosting

GitHub is super awesome, until you have to start paying for it. Check out two feature-full and FREE alternatives.

Jan 08, 2015