[{"data":1,"prerenderedAt":578},["ShallowReactive",2],{"articles-an-elegant-way-of-managing-your-dot-files-with-git":3},{"id":4,"title":5,"body":6,"date":559,"description":560,"extension":561,"image":562,"meta":563,"navigation":256,"path":565,"published":256,"seo":566,"snippet":567,"stem":568,"tags":569,"video":576,"__hash__":577},"articles\u002Farticles\u002Fan-elegant-way-of-managing-your-dot-files-with-git.md","An elegant way of managing your dot files with git",{"type":7,"value":8,"toc":550},"minimark",[9,18,21,28,33,36,39,43,46,49,64,94,108,114,161,164,202,206,209,212,218,221,229,232,238,241,293,296,300,303,366,373,458,461,481,484,488,499,503,511,515,546],[10,11,12,13,17],"p",{},"How to juggle all your configuration files between machines? a question probably asked many times. Lots of people store there configuration files or also so called dotfiles in git repos to more easily share them between machine. A commonly used method is having a repo with all the dotfiles in the $HOME directory and symbolic link the config files to the desired location like so ",[14,15,16],"code",{},"ln -s ~\u002F.dotfiles\u002F.zshrc ~\u002F.zshrc",". Syncing dotfiles with symbolic links can still be quite a chore especially when you clone your repo to a new machine and have to create all those symbolic links again.",[10,19,20],{},"Not to worry fortunately there is a more elegant way no more symbolic links and it only dependency is git.",[10,22,23,24,27],{},"How does it work, by making use of a bare repository you effectively only get the repository state without its working tree. With some flags you can use this repository with the ",[14,25,26],{},"$HOME"," directory as its working tree eliminating the need for carefully managing you symbolic links because all files are already in the right place. Neat right?",[29,30,32],"h2",{"id":31},"lest-get-started","Lest get started",[10,34,35],{},"If you have not tracked you dotfiles in a git repo you can get started in the next section right away..",[10,37,38],{},"If you already have a repository skip to the \"Migrate existing repository\".",[29,40,42],{"id":41},"setup-from-scratch","Setup from scratch",[10,44,45],{},"If you already track your dotfiles in a git repository.",[10,47,48],{},"with setting up your own dotfiles repo.",[10,50,51,52,55,56,59,60,63],{},"First things first lets create a folder for the bare repo ",[14,53,54],{},"mkdir ~\u002F.dots","\nnext we ",[14,57,58],{},"cd ~\u002F.dots"," and run ",[14,61,62],{},"git init --bare"," to setup our bare repo.",[10,65,66,67,70,71,74,75,78,79,70,82,85,86,89,90,93],{},"Next we're going to add an alias to our ",[14,68,69],{},"~\u002F.zshrc"," or ",[14,72,73],{},"~\u002F.bashrc","\nadd ",[14,76,77],{},"alias dots='\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'"," to a place of you liking, save and run ",[14,80,81],{},"source ~\u002F.zshrc",[14,83,84],{},"source ~\u002F.bashrc",".\nNow you can use the ",[14,87,88],{},"dots"," alias just as how you normally use the ",[14,91,92],{},"git"," command in a project folder.",[10,95,96,97,100,101,104,105,107],{},"Lets check our repos status with ",[14,98,99],{},"dots status",". As you can see git tries to make you aware that all you files in the home directory are untracked. this makes things a bit unclear. We can solve this by configuring the repo to only show changes that are already tracked by running ",[14,102,103],{},"dots config --local status.showUntrackedFiles no",". If we now run ",[14,106,99],{}," again we see there are no changes in the working tree.",[10,109,110,111,113],{},"We are all set to start tracking files. Lets commit our ",[14,112,69],{},".",[115,116,121],"pre",{"className":117,"code":118,"language":119,"meta":120,"style":120},"language-bash shiki shiki-themes github-light github-dark","dots status\ndots add ~\u002F.zshrc\ndots commit -m \"feat: add zsh config\"\n","bash","",[14,122,123,135,146],{"__ignoreMap":120},[124,125,128,131],"span",{"class":126,"line":127},"line",1,[124,129,88],{"class":130},"sScJk",[124,132,134],{"class":133},"sZZnC"," status\n",[124,136,138,140,143],{"class":126,"line":137},2,[124,139,88],{"class":130},[124,141,142],{"class":133}," add",[124,144,145],{"class":133}," ~\u002F.zshrc\n",[124,147,149,151,154,158],{"class":126,"line":148},3,[124,150,88],{"class":130},[124,152,153],{"class":133}," commit",[124,155,157],{"class":156},"sj4cs"," -m",[124,159,160],{"class":133}," \"feat: add zsh config\"\n",[10,162,163],{},"The only thing left to do is to add a remote and push our changes.",[115,165,167],{"className":117,"code":166,"language":119,"meta":120,"style":120},"dots remote add origin \u003Cyour-remote-repository>\ndots push\n",[14,168,169,195],{"__ignoreMap":120},[124,170,171,173,176,178,181,185,188,192],{"class":126,"line":127},[124,172,88],{"class":130},[124,174,175],{"class":133}," remote",[124,177,142],{"class":133},[124,179,180],{"class":133}," origin",[124,182,184],{"class":183},"szBVR"," \u003C",[124,186,187],{"class":133},"your-remote-repositor",[124,189,191],{"class":190},"sVt8B","y",[124,193,194],{"class":183},">\n",[124,196,197,199],{"class":126,"line":137},[124,198,88],{"class":130},[124,200,201],{"class":133}," push\n",[29,203,205],{"id":204},"migrate-existing-repository","Migrate existing repository",[10,207,208],{},"If you are setting up from scratch you can skip this section.",[10,210,211],{},"If you already track your files in a git repository you can easily migrate to this approach.",[10,213,214,215,217],{},"First off make sure the file and folder structure of your current dotfile repository mirrors your ",[14,216,26],{}," folder one to one.",[10,219,220],{},"For example something like this.",[115,222,227],{"className":223,"code":225,"language":226},[224],"language-text","dotfiles\n│   README.md\n│   .zshrc    \n│   .gitconfig\n│\n└───alacritty\n│   │   alacritty.conf\n│   \n└───htop\n    │   htoprc\n","text",[14,228,225],{"__ignoreMap":120},[10,230,231],{},"Should be changed to resemble your home directory like so.",[115,233,236],{"className":234,"code":235,"language":226},[224],"dotfiles\n│   README.md\n│   .zshrc    \n│   .gitconfig\n│\n└───.config\n    │\n    └───alacritty\n    │   │   alacritty.conf\n    │\n    └───htop\n        │   htoprc\n",[14,237,235],{"__ignoreMap":120},[10,239,240],{},"Next add this alias to you shell configuration file.",[115,242,244],{"className":117,"code":243,"filename":69,"language":119,"meta":120,"style":120},"# ~\u002F.zshrc\n\n...\n\nalias dots='\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'\n\n...\n",[14,245,246,252,258,263,268,283,288],{"__ignoreMap":120},[124,247,248],{"class":126,"line":127},[124,249,251],{"class":250},"sJ8bj","# ~\u002F.zshrc\n",[124,253,254],{"class":126,"line":137},[124,255,257],{"emptyLinePlaceholder":256},true,"\n",[124,259,260],{"class":126,"line":148},[124,261,262],{"class":156},"...\n",[124,264,266],{"class":126,"line":265},4,[124,267,257],{"emptyLinePlaceholder":256},[124,269,271,274,277,280],{"class":126,"line":270},5,[124,272,273],{"class":183},"alias",[124,275,276],{"class":190}," dots",[124,278,279],{"class":183},"=",[124,281,282],{"class":133},"'\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'\n",[124,284,286],{"class":126,"line":285},6,[124,287,257],{"emptyLinePlaceholder":256},[124,289,291],{"class":126,"line":290},7,[124,292,262],{"class":156},[10,294,295],{},"From then on it's the same as setting up a fresh machine follow the instructions from the next section to complete your migration.",[29,297,299],{"id":298},"setup-a-new-machine","Setup a new machine",[10,301,302],{},"To install your dotfiles to a new machine looks something like this.",[115,304,306],{"className":117,"code":305,"language":119,"meta":120,"style":120},"git clone --bare \u003Cyour-remote-repository> ~\u002F.dots\nalias dots='\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'\ndots config --local status.showUntrackedFiles no \ndots checkout\n",[14,307,308,330,340,359],{"__ignoreMap":120},[124,309,310,312,315,318,320,322,324,327],{"class":126,"line":127},[124,311,92],{"class":130},[124,313,314],{"class":133}," clone",[124,316,317],{"class":156}," --bare",[124,319,184],{"class":183},[124,321,187],{"class":133},[124,323,191],{"class":190},[124,325,326],{"class":183},">",[124,328,329],{"class":133}," ~\u002F.dots\n",[124,331,332,334,336,338],{"class":126,"line":137},[124,333,273],{"class":183},[124,335,276],{"class":190},[124,337,279],{"class":183},[124,339,282],{"class":133},[124,341,342,344,347,350,353,356],{"class":126,"line":148},[124,343,88],{"class":130},[124,345,346],{"class":133}," config",[124,348,349],{"class":156}," --local",[124,351,352],{"class":133}," status.showUntrackedFiles",[124,354,355],{"class":133}," no",[124,357,358],{"class":190}," \n",[124,360,361,363],{"class":126,"line":265},[124,362,88],{"class":130},[124,364,365],{"class":133}," checkout\n",[10,367,368,369,372],{},"Running ",[14,370,371],{},"dots checkout"," can result in something like this.",[115,374,376],{"className":117,"code":375,"language":119,"meta":120,"style":120},"error: The following untracked working tree files would be overwritten by checkout:\n    .zshrc\nPlease move or remove them before you can switch branches.\nAborting\n",[14,377,378,416,421,453],{"__ignoreMap":120},[124,379,380,383,386,389,392,395,398,401,404,407,410,413],{"class":126,"line":127},[124,381,382],{"class":130},"error:",[124,384,385],{"class":133}," The",[124,387,388],{"class":133}," following",[124,390,391],{"class":133}," untracked",[124,393,394],{"class":133}," working",[124,396,397],{"class":133}," tree",[124,399,400],{"class":133}," files",[124,402,403],{"class":133}," would",[124,405,406],{"class":133}," be",[124,408,409],{"class":133}," overwritten",[124,411,412],{"class":133}," by",[124,414,415],{"class":133}," checkout:\n",[124,417,418],{"class":126,"line":137},[124,419,420],{"class":130},"    .zshrc\n",[124,422,423,426,429,432,435,438,441,444,447,450],{"class":126,"line":148},[124,424,425],{"class":130},"Please",[124,427,428],{"class":133}," move",[124,430,431],{"class":133}," or",[124,433,434],{"class":133}," remove",[124,436,437],{"class":133}," them",[124,439,440],{"class":133}," before",[124,442,443],{"class":133}," you",[124,445,446],{"class":133}," can",[124,448,449],{"class":133}," switch",[124,451,452],{"class":133}," branches.\n",[124,454,455],{"class":126,"line":265},[124,456,457],{"class":130},"Aborting\n",[10,459,460],{},"You have two options:",[462,463,464,471],"ol",{},[465,466,467,468,113],"li",{},"overwrite the existing files if you feel confident you are not losing anything by running ",[14,469,470],{},"dots checkout -f",[465,472,473,474,477,478,480],{},"backup the existing files by renaming them like so ",[14,475,476],{},"mv ~\u002F.zshrc ~\u002F.zshrc.backup"," and when you're done, to backup your files run ",[14,479,371],{}," again.",[10,482,483],{},"At this point all your dotfiles should be in the right place.",[29,485,487],{"id":486},"alternatives","Alternatives",[10,489,490,491,498],{},"I prefer this method of managing dotfiles for its simplicity, but this is just one approach of many. If you're interested in other ways of managing your dotfiles I recommend checking out ",[492,493,497],"a",{"href":494,"rel":495},"https:\u002F\u002Fdotfiles.github.io\u002F",[496],"nofollow","dotfiles.github.io",". It has a lot of references of other people's dotsfiles, tutorials and projects centered around dotfiles.",[29,500,502],{"id":501},"wrapping-up","Wrapping up",[10,504,505,506,113],{},"Hope this post helps out a fellow developer on their config journey. If you have any questions or feedback you're always welcome to send me a message on ",[492,507,510],{"href":508,"rel":509},"https:\u002F\u002Ftwitter.com\u002FLiamEderzeel",[496],"@liamederzeel",[29,512,514],{"id":513},"sources","Sources",[516,517,518,528,537],"ul",{},[465,519,520,523,524],{},[124,521,522],{},"1"," ",[492,525,526],{"href":526,"rel":527},"https:\u002F\u002Fnews.ycombinator.com\u002Fitem?id=11070797",[496],[465,529,530,523,533],{},[124,531,532],{},"2",[492,534,535],{"href":535,"rel":536},"https:\u002F\u002Fwww.atlassian.com\u002Fgit\u002Ftutorials\u002Fdotfiles",[496],[465,538,539,523,542],{},[124,540,541],{},"3",[492,543,544],{"href":544,"rel":545},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=tBoLDpTWVOM",[496],[547,548,549],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":120,"searchDepth":137,"depth":137,"links":551},[552,553,554,555,556,557,558],{"id":31,"depth":137,"text":32},{"id":41,"depth":137,"text":42},{"id":204,"depth":137,"text":205},{"id":298,"depth":137,"text":299},{"id":486,"depth":137,"text":487},{"id":501,"depth":137,"text":502},{"id":513,"depth":137,"text":514},"2022-07-29","How to juggle all your configuration files between machines? a question probably asked many times. Lots of people store there configuration files or also so called dotfiles in git repos to more easily share them between machine. A commonly used method is having a repo with all the dotfiles in the $HOME directory and symbolic link the config files to the desired location like so ln -s ~\u002F.dotfiles\u002F.zshrc ~\u002F.zshrc. Syncing dotfiles with symbolic links can still be quite a chore especially when you clone your repo to a new machine and have to create all those symbolic links again.","md","\u002Fimages\u002Fdot-files.png",{"slug":564},"an-elegant-way-of-managing-your-dot-files-with-git","\u002Farticles\u002Fan-elegant-way-of-managing-your-dot-files-with-git",{"title":5,"description":560},"How to use a git bare repo to manage and sync your dotfiles the easy why.","articles\u002Fan-elegant-way-of-managing-your-dot-files-with-git",[570,571,572,573,574,575],"Linux","Config","Bash","Zsh","Terminal","Git",null,"NBMerbxK6qgbZ4h_PZrCqlAVsRR_hpQL-lwM2GyTfEg",1793104389256]