After I because comfortable with running my own private git server I began experimenting with storing my home directory as repository. The main benefit of this is that I would am able to keep my home directory synchronized across numerous machines. For instance I have aa desktop at work, a laptop at home, a dev vm and a few servers. I like to have the same tools and familiar prompts on all machines and keeping this all in sync manually is a real chore.
As with any new concept there is always learning curve but I felt that the benefits far outweighed the time invested. So aside form have my environment setup on each machine the way I prefer with things like login script, nano resources, .bin scripts I also started experimenting with the idea of having git stage directory stubs as well as an extreme git concept of repositories within other repositories. We will save that higher level concept for another article. If you missed the discussion about setting up your own private repository server then please check it out Serving Git with FreeBSD.
Keeping this all in sync manually is a real chore, but git makes it easy just like magick!
So after cloning the repo and manually moving the pieces into place as I have note riddled out a way to get git to clone into a live directory with files already in place. Obviously this was only necessary to get things rolling once I had it up and running I am able to just do a home directory swap. Now that the how directory is setup I have something like the following:
Ok now I admit that does not look very impressive so let’s take a closer look.
The problem is I wanted to have more than my projects folder readied. I wanted the git & svn stubs in place. So this is how I pulled that off. We’ll look at my projects container.
excerpt original .gitignore:
Projects/untracked
Projects/svn
Projects/git
Projects/.metadata
Projects/scratch
Since I did not want my home repository to collect me various projects I had to eliminate them from the version control system’s scope. Using the same .gitignore file I added each specific project to the list.
excerpt new .gitignore:
Projects/untracked
Projects/svn
Projects/git/clt
Projects/git/development-tools
Projects/git/rdc
Projects/git/wordpress
Projects/.metadata
Projects/scratch
Since modifying the .gitignore
# On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: .gitignore # no changes added to commit (use "git add" and/or "git commit -a")
Unfortunately this still have given me the git subdirectory stub that I was looking for. Therefore I added Projects/git/README.md which now informs git that there is something of interest inside of the git subdirectory.
# On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: .gitignore # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Projects/git/ no changes added to commit (use "git add" and/or "git commit -a")
Git now sees the Projects/git path because it knows there is a file that is currently untracked. By performing the add command on Projects/git/ I make make that file visible. I am now able to commit this work and push it up to the master on origin.
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: Projects/git/README.md # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: .gitignore #
This is handy because now I have ensured that my git projects directory will be created by git when I clone my home directory onto a new machine. Obviously, this is nothing earth shatteringly huge but if you are unfamiliar with some of the intricacies of git then perhaps this will help shed some light. I believe this technique will help your gitfu.
Whether you are doing something routine or rather unusual, I am fairly certain that others would love to hear about it. So please take a moment to share this article and leave a note about your gitfu in the comments!
Leave a Reply