Skip to content

Instantly share code, notes, and snippets.

@dominikb1888
Created December 22, 2021 20:05
Show Gist options
  • Select an option

  • Save dominikb1888/87f396d8c8434fa284c91d17cdc2bd66 to your computer and use it in GitHub Desktop.

Select an option

Save dominikb1888/87f396d8c8434fa284c91d17cdc2bd66 to your computer and use it in GitHub Desktop.
Create a horizontal split in vim for the same file in different branches
function brdiff
set -l paths
for branch in (git branch -l | fzf -m | tr -d '[*+ ]')
if [ $branch = "master" ]
set -a paths $argv[1]
else
git worktree add "../$branch"
set -a paths "../$branch/$argv[1]"
end
end
echo $paths
vim -O $paths
end
@dominikb1888
Copy link
Author

Only works if master is checked out in the current git folder. New worktrees will be generated in parent folder.

TODO:

  • Check for current branch instead of hard coded "master"

An improved version would probably check out a new bare repo first and then do add the worktrees.

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