2020-04-30 06:14:46 +00:00
---
title: "Dotfiles With Git"
date: 2020-04-29T13:26:01+02:00
draft: true
tags:
- bash
- git
- dotfiles
---
# Simple way to manage dotfiles with git
I use a very simple way to manage my dotfiles with git and some bash aliases.
All you have to create a folder for your git repository in your home folder and initiate a bare git repository
```bash
2020-07-31 13:12:20 +00:00
mkdir "$HOME/.dotfiles"
git init --bare "$HOME/.dotfiles"
2020-03-30 06:50:50 +00:00
```
2020-04-30 06:14:46 +00:00
Then create an alias so you don't have to write a long command each time you want to add a file or configure your git repository, don't forget to add that alias to $HOME/.alias
```bash
2020-07-31 13:12:20 +00:00
alias dotf='/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
2020-03-30 06:50:50 +00:00
```
2020-04-30 06:14:46 +00:00
so, that alias is calling git and sets the repository as well as working directory and it can be called from what ever path you currently be in.
The next thing we need to do is to configure the repository to not show untracked files and only care about the files we specifically want to manage.
```bash
dotf config --local status.showUntrackedFiles no
2020-03-30 06:50:50 +00:00
```
2020-04-30 06:14:46 +00:00
Now you just use the dotfiles alias for git to add files, commit changes, etc, etc
```bash
dotf add .alias .bashrc
dotf commit -m "Added .alias and .bashrc"
2020-03-30 06:50:50 +00:00
```
2020-04-30 06:14:46 +00:00
To show the status of the repository
```bash
dotf status
2020-03-30 06:50:50 +00:00
```
2020-04-30 06:14:46 +00:00
if you want to add some bash completion to dotf you can just add the following line to your .bashrc
2020-03-30 06:50:50 +00:00
```
2021-11-18 15:07:03 +00:00
[[ $(type -t __git_complete) == function ]] & & __git_complete dotf __git_main
2020-04-30 06:14:46 +00:00
```
2021-11-18 16:40:14 +00:00
*I use my functions defined in [dotf.sh ](.functions/dotf.sh )*
2020-04-30 06:14:46 +00:00
If you want you can add a remote repository make sure that it's secure if you manage sensitive information.
```bash
dotf remote add origin < username > @git.domain.tld/dotfiles.git
dotf push
2020-03-30 06:50:50 +00:00
```
2020-08-03 12:03:36 +00:00
# To initialize my desktop run
```bash
bash < (curl -sL https://git.rre.nu/jonas/dotfiles/raw/branch/master/bin/initDesktop)
```