Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use git to manage home directory

Tags:

git

I'd like to create one single git repo in my Linux $HOME directory. In this repo - obviously - I could add everything under version control, but this wouldn't make any sense. I'd like to only add the files and folders that are relevant to me, like .vimrc, .vim, .bashrc, etc. (probably only hidden files and folders, but maybe not)

I know I could leverage .gitignore to try and achieve such behavior but that would be painful and virtually un-maintainable. Instead, what I'd want to know is if there'd be any way to manually declare files and folders that I would want to manage, and only that.

like image 484
Aurelien Navarre Avatar asked Jan 21 '14 19:01

Aurelien Navarre


People also ask

What is home directory in git?

By default Git wants to use your user directory as its home directory. This is where it wants to put all its configuration files and repositories; it is the default location that is opened when you start Git Bash.

How do I navigate folders in git?

Browse to the desired Directory through Commands in Git Bash Open your Git Bash. Type the following command cd <path of the directory> and press enter.

Does git work on folders?

All of the local git "stuff" is placed in the . git folder in your "local repos" a.k.a. "working folder/directory". Folder/directory here is a folder that can contain other folders/directories - as well as files - indeed it will always contain a . git folder, otherwise it would not be a repository.


2 Answers

.gitignore

# Ignore everything *  # But not these files... !*.vimrc !*.vim !*.bashrc !.gitignore  # etc... 

My home directory is also on GitHub.

like image 114
Niklas Avatar answered Sep 22 '22 16:09

Niklas


I would setup an alias for use only with your home repo this way you can use the alias in place of git command and you always know the context you are working in

# .bashrc alias home='git --work-tree=$HOME --git-dir=$HOME/.home' 

Issuing the comand

$ home init 

will create a repo in .home folder in your $HOME and irrelevant of current directory you can work with your home repo with the alias 'home' in place of 'git'

This alongside a .gitignore should be all you need.

# .gitignore * # keep track !.bashrc !.gitignore 

NB. DO NOT KEEP .ssh/keys in repo as it presents file permission and security issues.

like image 38
Pete Avatar answered Sep 19 '22 16:09

Pete