Skip to content

Instantly share code, notes, and snippets.

@afair
Last active May 21, 2019 07:48
Show Gist options
  • Save afair/bb9d76aeb15b0524075a373ca37c5994 to your computer and use it in GitHub Desktop.
Save afair/bb9d76aeb15b0524075a373ca37c5994 to your computer and use it in GitHub Desktop.
Merge/Rebase with git mergetool vimdiff usage

Using 'vimdiff' as your git mergetool

.vimrc

" vimdiff
if &diff
  map <silent> <leader>1 :diffget LOCAL<CR>
  map <silent> <leader>2 :diffget BASE<CR>
  map <silent> <leader>3 :diffget REMOTE<CR>
  map <silent> <leader>u :diffupdate<CR>
  map <silent> <leader>s :wqall<CR>
  map ] ]c
  map [ [c
  map <leader>n ]c
  map <leader>p [c
  map <leader>u :diffupdate<CR>
endif

.gitconfig

# Rebase workflow
[mergetool]
  prompt = false
[merge]
  tool             = vimdiff
[alias]
  rc               = rebase --continue
  mt               = mergetool
  au               = add -u
  uu               = !git --no-pager diff --name-only --diff-filter=U
  kn               = checkout --theirs # "keep new" --theirs is new work
  ko               = checkout --ours # "keep old"   --ours is base branch (rebase branch)

Workflow

Start by either:

git rebase master
git merge feature-branch

Iterate through conflicts:

git uu       # Show conflicted file
git mt       # Runs vimdiff
git kn files # Keep the new version (--theirs)
git ko files # Keep the old version (--ours)
git au       # Adds fixed files
git rc       # Continues rebase/merge

git rebase --abort # Surrender

Note: "ours/theirs" perspective is of owner of base branch merging in work branch, so --our is old/base, --theirs is new/work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment