Tom Hale
Tom Hale

Reputation: 46953

Manage dotfiles merge conflicts in git config without breaking git

I manage my config files in a git repository in ~/.dotfiles and deploy them with stow.

Sometimes I come across errors like:

First, rewinding head to replay your work on top of it...
Applying: tmux: put newer version commands inside if-block
fatal: bad config line 149 in file /home/ravi/.config/git/config
Cannot store 5639c86778d99ec6b34c93bfd4d122c1cbb379a8

git is complaining because its config file has bad syntax - because of a yet unresolved merge conflict, the config file now includes lines like:

<<<<<<< A
lines in file A
=======
lines in file B
>>>>>>> B

Every time this happens I need to:

  1. git rebase --abort
  2. cp ~/.config/git/config ~/.gitconfig (.gitconfig is used preferentially)
  3. Complete the operation that had the initial failure
  4. Remember to delete ~/.gitconfig

How can I automate the config copy to ~/.gitconfig and subsequent removal?

Upvotes: 1

Views: 256

Answers (1)

torek
torek

Reputation: 489083

This is a very interesting problem.

I recommend avoiding it. :-)

I keep a set of dot-files (including a $HOME/.gitconfig file) in a Git repository, but I don't use this Git repository's work-tree as the actual dot-files.1 Hence, if conflicts occur, they don't affect the actual dot-files.


1This is only true on some systems, but I avoid merging on systems where a home-directory dot-file is a hard or symbolic link to a dotfiles-work-tree copy.

Upvotes: 1

Related Questions