Home » Programming » I’m a git and I love it
        

I’m a git and I love it

I use git, and I love it. I use it to hold my personal code and textual files, and I use it to share the code I use on this site, and the code pasted in some of the articles. There is, as always, a lot of contention over svn vs git vs mercurial… but that’s not the point of this article. (Though, I confess, mercurial being written in python tells me I might enjoy fiddling with it.)

The point of this article is, I love git. Most of the time, I don’t even realize I need a repository until … well until I need one. I’m a big fan of bare repos, so thats what I’ll write about. Also, I’ll talk about multiple remote repositories, which is how I manage to keep my pre-published code separate from the github repo I have linked with this blog.

I have three1 github2 plugins3 for WordPress to supply the code to my blog, and I use wp-syntax (or try this for instructions) to colour it up using the fantastic GeSHi highlighting engine and display it.

Git is in all the major distros, and most package managers have a “git” you can install, plus you can find instructions for installing from source, so if you’re a masochist, you can install it on your droid or mini Linux box. There are also a lot of options for Windows. (You can also install git via git…..)

 

So, once you install git, you want a new repo, right? Well, usually, if you are like me, you want a bucket to hold your stuff, something you can organize, push and pull from multiple locations.

* Most of my notes are from Pro Git by Scott Chacon, the git book freely available on the git-scm website.

Often, online, you see repos being set up ending in .git. This is a convention I do not follow.

For a bare repo, go to or mkdir the empty directory, and run


git init --bare

 

Then, you can move in the files you need, or at least touch a file.

The usual commands are:

 

git pushgit commit (or frequently git commit -a),  git pull


man git and git --help are also of some use.

 

Now, once you get the push-pull working for ya, there’s some additional tricks, like your config file in /.git/config. I keep my repo on a remote server from my home, so I have both that repo, and the one I use on github to share code on here.

 

Mine looks like:

/weetabytes/blob/master/git_config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = ssh://<user>@<myserver>/repos/git/weetabytes
[branch "master"]
	remote = origin
	merge = refs/heads/master
[remote "github"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = ssh://git@github.com/weetabix/weetabytes.git
[remote "all"]
	url = ssh://<user>@<myserver>/repos/git/weetabytes
	url = ssh://git@github.com/weetabix/weetabytes.git

This allows me to do fun stuff, like, after a commit, doing git push github, or git push master, if I only want to update one place, I can do git push all to push to all repos, or I can do git push origin github to make sure both remote repos are up to speed with each other, without my copy being included.

If you are sharing to mostly Linux users, SSH is awesome to use. If you have a large amount of Windows users, http/s allows you to get away without using another program like plink.

Talk to you later,

 

-weetabix

Leave a Reply