{"id":1808,"date":"2024-02-12T00:04:00","date_gmt":"2024-02-12T00:04:00","guid":{"rendered":"https:\/\/carlosfx.com\/?p=1808"},"modified":"2024-02-08T10:58:41","modified_gmt":"2024-02-08T10:58:41","slug":"how-to-manage-dotfiles-in-windows-yes-you-read-that-right-windows","status":"publish","type":"post","link":"https:\/\/carlosfx.com\/de\/2024\/02\/how-to-manage-dotfiles-in-windows-yes-you-read-that-right-windows\/","title":{"rendered":"How to manage dotfiles in Windows, yes you read that right, Windows."},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Some backstory.<\/h2>\n\n\n\n<p>If you want to skip this section, <a href=\"#tutorial-part\">click here<\/a>.<\/p>\n\n\n\n<p>I&#8217;ve been using VSCode on Windows for about two years, I&#8217;m new to programming and come from the construction industry as you can see on this website, I&#8217;m kind of tied to the Windows OS or as some people call it William G. Telemetry, also known as MS Telemetry, <strong>so switching to Linux is not an option<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Vim in the future?<\/h4>\n\n\n\n<p>I&#8217;ve been checking twitter lately and there&#8217;s a lot of talk about NeoVim and decided to give it a try, learn a bit more about it and of course the configuration side of it, and maybe one day I can replace VSCode.<\/p>\n\n\n\n<p>I&#8217;ve used Vim to edit small text files, but nothing more, already mastered hjkl and :wq! and never needed anything else, so my learning path started by reading the Vim docs and the NeoVim docs, then started watching a video from TypeCraft and so far I&#8217;m happy with the results.<\/p>\n\n\n\n<p>But after watching the first video he mentioned something about the dotfiles folder, and reading further about it I thought it would be a good idea to save my configuration to be used on other computers. So I decided to look for a solution.<\/p>\n\n\n\n<p>There are some solutions like creating symbolic links, which are similar in Linux, but luckily searching on YouTube I found a video from the DistroTube, a channel I watch from time to time because of its professional lookng videos, (<a href=\"https:\/\/youtu.be\/tBoLDpTWVOM\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/youtu.be\/tBoLDpTWVOM<\/a>), in the video he shows a solution to manage the dotfiles using a git bare repository, so I watched the video, read the article that inspired his video and started on my way to create my dotfiles report.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tutorial-part\">Tutorial part<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">This is currently the best solution I&#8217;ve found, so if you find something better or know of another solution, please share it, I&#8217;d love to hear some ideas.<\/h4>\n\n\n\n<h3 class=\"wp-block-heading\">My setup<\/h3>\n\n\n\n<p>I&#8217;m using<br>&#8211; Cmder (<a href=\"https:\/\/cmder.app\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/cmder.app\/<\/a>), a portable console emulator, with cmd from Windows<br>&#8211; Git<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Folders<\/h3>\n\n\n\n<p>I have two directories for this tutorial, the <strong>dotfiles<\/strong> directory with my files and a <strong>dotrepo<\/strong> directory.<\/p>\n\n\n\n<p>The <strong>dotfiles<\/strong> directory is my working directory, usually in Windows the config files are stored in the C:\\Users\\<\/p>\n\n\n\n<p>Be careful, there&#8217;s an AppData directory which may contain some other config files, in the Local and Roaming subdirectories, so check where your program stores the config files, and you have to take care of the subfolders using a .gitignore file, or you can add your dotfiles manually.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Run cmd, cmd or power shell as admin.<\/h4>\n\n\n\n<p>Inside the <strong>dotrepo<\/strong> directory run <code>git init --bare<\/code>, this will create a bare repository with no working tree, this is not a normal git directory because you won&#8217;t be adding files to it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"987\" height=\"207\" src=\"https:\/\/carlosfx.com\/wp-content\/uploads\/2024\/02\/cmd01.png\" alt=\"\" class=\"wp-image-1810\"\/><\/figure>\n\n\n\n<p>Now you can go into the <strong>dotfiles<\/strong> directory and add a file, in my case I added a <strong>*README.md<\/strong>.<\/p>\n\n\n\n<p>Then run the following command<br>git &#8211;git-dir=D:\\example\\dotrepo\\ &#8211;work-tree=D:\\example\\dotfiles\\ status`.<\/p>\n\n\n\n<p>You can see that the file we just created is shown as untracked.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"188\" src=\"https:\/\/carlosfx.com\/wp-content\/uploads\/2024\/02\/cmd02.png\" alt=\"\" class=\"wp-image-1811\"\/><\/figure>\n\n\n\n<p>The <code>--git-dir=<path><\/path><\/code> command tells git where the git naked directory is, and the <code>--work-tree=<path><\/path><\/code> command tells git where the working tree is.<\/p>\n\n\n\n<p>The <strong>\\&#8220;&#8211;git-dir=D:\\example\\dotrepo\\&#8220; and &#8222;&#8211;work-tree=D:\\example\\dotfiles\\&#8220;<\/strong> are all the magic in this process.<\/p>\n\n\n\n<p>For example, we can add, commit and push the README<br>&#8211; git add README.md<br>&#8211; <code>git <flags> commit -m \"First file added\"'<\/flags><\/code><br>&#8211; <code>git <flags> push<\/flags><\/code>.<br>&#8211; <code>git <flags> status<\/flags><\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"501\" src=\"https:\/\/carlosfx.com\/wp-content\/uploads\/2024\/02\/cmd03.png\" alt=\"\" class=\"wp-image-1812\"\/><\/figure>\n\n\n\n<p>For example, you can configure your username, password, and URLs in your <strong>git bare folder<\/strong> using the same method<\/p>\n\n\n\n<p>git <flags> config &#8211;local user.email &#8222;<useremail>&#8222;<br>git <flags> config &#8211;local user.name &#8222;<username>&#8222;<br>git <flags> config &#8211;local remote.origin.url &#8222;<repourl>&#8222;<\/repourl><\/flags><\/username><\/flags><\/useremail><\/flags><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Important<\/h3>\n\n\n\n<p>When you use <code>git <flags> status<\/flags><\/code> you will notice that everything in the folder will be listed as untracked, <strong>you have to add the files and folders manually<\/strong>, don&#8217;t add everything to wsing git.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cmder aliases<\/h3>\n\n\n\n<p>If you don&#8217;t want to type the long commands every time you can use <a href=\"https:\/\/github.com\/cmderdev\/cmder\/wiki\/Cmder-Aliases\" target=\"_blank\" rel=\"noreferrer noopener\">cmder aliases<\/a>, and of course if you&#8217;re in the command prompt or using powershell you can add aliases too, I just prefer cmder because it&#8217;s easy to configure.<\/p>\n\n\n\n<p>The file with the aliases can be found iside the cmder directory in &#8230;cmder\\config\\user_aliases.cmd<\/p>\n\n\n\n<p>Let&#8217;s look at the alias in Cmder for our case.<br><code>dgit=git --git-dir=D:\\example\\dotrepo\\ --work-tree=D:\\example\\dotfiles\\ $*<\/code><\/p>\n\n\n\n<p>Where <code>dgit=<\/code> is the alias name.<br>The magic is <code>git --git-dir=D:\\example\\dotrepo\\ --work-tree=D:\\example\\dotfiles\\ and<\/code>$*` tells cmder that flags can be added at the end of the command.<\/p>\n\n\n\n<p>After editing and reloading the aliases in cmder, you can then run<br>`dgit status&#8216; and you will get the status of the bare git repository.<\/p>\n\n\n\n<p>Please note that if you do not add <code>$*<\/code> to the end of the alias, Cmder will ignore the flags that come after the command, i.e. you will only run the <code>git<\/code> command which shows the usage of git.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Caveats<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Manually added files<\/h3>\n\n\n\n<p>It takes time to search with configuration files or folders, and then they have to be added one by one to the repo.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Empty folders<\/h3>\n\n\n\n<p>I mentioned already but this has to be clear, <strong>you have to add the files and directories manually<\/strong> <\/p>\n\n\n\n<p>For instance <code><strong>git <flags> add AppData\\Local\\nvim<\/flags><\/strong><\/code>.<\/p>\n\n\n\n<p><br>Add the files to the repository with the full path with empty directories, in my case some files are in <strong>C:\\Users\\AppData\\Local\\nvim<\/strong>, the configuration files for neovim are added to the repo as <em><strong>AppData\\Local\\nvim<\/strong><\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other files<\/h3>\n\n\n\n<p>Configuration files outside C:\\Users\\<username> can&#8217;t be tracked using git, everything has to be in the work-tree.<\/username><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some backstory. If you want to skip this section, click here. I&#8217;ve been using VSCode on Windows for about two years, I&#8217;m new to programming and come from the construction industry as you can see on this website, I&#8217;m kind of tied to the Windows OS or as some people call it William G. Telemetry, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1810,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[239],"tags":[249,247,235],"class_list":["post-1808","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-config","tag-dotfiles","tag-terminal"],"_links":{"self":[{"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":11,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"predecessor-version":[{"id":1828,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/posts\/1808\/revisions\/1828"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/media\/1810"}],"wp:attachment":[{"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carlosfx.com\/de\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}