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