david alfonso

Updating my Neovim config from upstream

When I picked a reference Neovim config, one of the main criteria was that it should be updated regularly. This note explains how to bring updates from the upstream repository (i.e. LunarVim/Launch.nvim) to my own config repo.

Bringing changes from upstream to main branch

Creating the repo from a GitHub template only makes it reference the original repo but it's not a real fork and commits are completely unrelated. This means that I can't use any GitHub feature to deal with forked repositories and the process will be manual.

Let's see it step by step.

  1. Add upstream as a remote to the local clone, if not done already:
$ git remote add upstream https://github.com/LunarVim/Launch.nvim
  1. Fetch changes from upstream
$ git fetch --all
  1. Merge remote master branch with local master branch
$ git checkout master

# The first time you merge from upstream the unrelated histories flag is
# required
$ git merge upstream/master --allow-unrelated-histories

# After the first time, we can just merge
$ git merge upstream/master
  1. Rebase my mine branch (the one which contains my changes) with master
    • Note: This could be a merge but I don't want to preserve the commits, as I'm the sole user of this repo.
$ git checkout mine

$ git rebase master
  1. Push changes to remote origin repo
# Force should not be required
$ git push origin master

# We have rebased mine, so let's force push
$ git push -f origin mine

Updating the submodule commit in my dotfiles repo

Now that my nvim-config repo is updated, I can do the same with my dotfiles repo which references the former with a submodule.

  1. Cd home, because my dotfiles are my home directory.
$ cd
  1. Pull changes from the just updated remote nvim-config into the local submodule clone.
    • Note: The commit referenced in the mine branch is the one we want our submodule to point to.
$ git fetch --recurse-submodules origin
Fetching submodule .config/nvim
From https://github.com/davidag/nvim-config
   ea52394..2d88040  master     -> origin/master
 + f9f407d...e51cad0 mine       -> origin/mine  (forced update)
  1. Make the submodule HEAD point to the new commit
# -C: Cd to the submodule local path before running the Git command
$ git -C .config/nvim reset origin/mine
  1. Push submodule change
# Only a file is modified when updating a submodule
# Verify that the new commit is the one shown in the step above
# (!) If the hash ends in -dirty, you need to enter ~/.config/nvim and clean the repo
$ git diff
diff --git a/.config/nvim b/.config/nvim
index f9f407d..e51cad0 160000
--- a/.config/nvim
+++ b/.config/nvim
@@ -1 +1 @@
-Subproject commit f9f407df596755ad6e03a63e83d6d8ca5c58dcc2
+Subproject commit e51cad0f5dffef66a4a401a1558712f67884c33d

# This force is required because my `.gitignore` contains `*` (this is not
# related to the process described here)
$ git add -f .config/nvim

# Commit the change
$ git commit

# Update origin
$ git push origin

Conclusions

This setup has several advantages: