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.
- Add upstream as a remote to the local clone, if not done already:
$ git remote add upstream https://github.com/LunarVim/Launch.nvim
- Fetch changes from upstream
$ git fetch --all
- Merge remote
master
branch with localmaster
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
- Rebase my
mine
branch (the one which contains my changes) withmaster
- 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
- 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.
- Cd home, because my
dotfiles
are my home directory.
$ cd
- 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.
- Note: The commit referenced in the
$ 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)
- 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
- 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:
- Upstream changes are brought into the
nvim-config master
branch without conflicts - My modifications to the original config live in a different branch,
mine
, and are easily viewable - I can work on my
nvim-config
directly in the submodule and quickly try new config options - Multiple commits in my neovim config can be translated into one commit in the
dotfiles
repo, leading to different Git history granularities