Useful git aliases

Here’s some useful git configurations and aliases. ┬áThe way you make a git alias is as follows:

$ git config --global checkout
$ git config --global branch
$ git config --global commit
$ git config --global status

You can use git config to also set various items such as the diff.tool, which uses gvimdiff whenever you use git difftool.  This makes the diffs much more visually understandable since you can scroll and see more context.

alias.loga=log --oneline -15 --graph --decorate --all
alias.rev=remote -v
alias.lst=ls-tree --abbrev -l HEAD
core.pager=less -r
bash debian git Uncategorized vim

cryptsetup and quickfix

2 unrelated things which I fixed up today. First, a few days ago my Fujitsu P7320, which I am very fond of, had its HD fail. So it’s off being repaired, presumably returning with a fresh HD. I used it often to transfer files between my various machines using git – although git is a dvcs, i was also using it to sync machines, leading to lots of illogical commits, which I’m sure some purist would say is appalling, but it works and works fast, and so far I haven’t had trouble. But now that the Fujitsu is out, I needed to use a thumbdrive. Last time I used one for syncing, i lost it for some time, then weeks later found when the snow in my driveway melted. (Amazingly, it still worked.) But while it was lost I was always worried about whether there were any important passwords cc’s etc on the drive. I determined to never use an unencrypted thumbdrive again. So today I had to get it encrypted in a hurry, and I found the relevant commands and they were simple, so here they are:
[sourcecode lang=”bash”]
cryptsetup luksFormat /dev/sdX
cryptsetup luksOpen /dev/sdX thumbdrive
# enter password
mkfs.ext2 /dev/mapper/thumbdrive
mount /dev/mapper/thumbdrive /media/thumbdrive
# do whatever

Much easier than I was expecting.

The second thing I rediscovered was quickfix on vim with g++. I was doing some simple editing of a single C++ file, and I wanted quickfix working again but I forgot everything. Here’s the lines from the .vimrc that make it go:

[sourcecode lang=”vim”]
set errorformat=%f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
set makeprg=g++\ -Wall\ -pedantic\ %\ -lm\ -lgsl\ -lgslcblas\ -o\ %<

That’s it. obviously later when using a makefile for real, I’ll have to modify the makeprg and make it.. just make.. but this works quick and dirty.

bash git

bash scripts for using git to sync laptops

I have 3 Debian laptops which I use daily. One at home, one at school, and one which I carry in my backpack. I’m also a backup nut. I have 4 external drives totaling 3.25T of storage which are for storing and backing each other up. For years I used rsync with linked files, which was alright but always had issues — sometimes the links wouldn’t propagate back properly for no apparent reason. I’d have the impression that things were working well when … really there was just the latest snapshot available.

Recently I’ve switched to unison for backing up things like photos and videos, which works great and has a nice GUI. It makes snapshots and just synchronizes the drives, with minimal muss and fuss.

But for my daily work, I want something with some history, like I had hoped to get from rsync, so I can revert a file to its previous state. I wanted something which wouldn’t have a ‘main’ copy and then child copies but rather where each laptop could function stand-alone and then quickly synchronize with the others whenever they were available. I wanted something which could run over ssh. I suspected git might do some of it, but I am surprised now how much of what I wanted, git does, and does well.

So I tried out git for while, but git has a steep learning curve. So steep that its the kind of thing which I abandon if I don’t get traction quickly, since I have little time to learn technical tools like this, especially tools which are not documented for beginners. (I’ve had that issue with OpenBSD, which seems like a nice OS, and which I’ve installed, but I’ve run into issues within the first day and then had to reformat over with Debian testing.)

However git has something which is an absolutely remarkable solution to this problem. There is an excellent, friendly git IRC channel at Several people there have given me such valuable advice specific to my situations that came up in the beginning that I’ve learned git to the point where it’s a tool that helps me so much I can’t do without it. There’s lots of primers and introductions out there, but I didn’t find one that really cut it for me; it is sorely needed, but the IRC channel makes up for its absence.

One key piece of advice I got was to avoid git push and pull in the beginning, and rather use git fetch and merge only. This was good advice, since you get a better sense of what each piece is doing, and it works.

So I wrote a couple of bash scripts which I use everyday and which I like. First I have in my .bashrc a line like

export GITDIRS=~/proj1:~/proj2:~/proj3

Whenever I need to sync up laptops I run the following bash script I call gitac (for git-add commit):


for gitdir in $GITDIRS; do 
    echo $gitdir 
    pushd $gitdir 
    git add .  
    git commit 

and then I ssh to the target laptop and run gitfr (for gitfrom):



for gitdir in $GITDIRS; do
    echo $gitdir 
    pushd $gitdir 
    git fetch $1:$gitdir HEAD 
    git merge FETCH_HEAD 

These work superfast and sync my laptops better than I could’ve asked for from rsync. I can see the commits graphically using gitk which is nice.

When I’m syncing my laptops it isn’t always a sensible time to do a significant commit on all my projects, but with git you can have several branches, one for daily working commits and another for significant commits — I’ve yet to completely work that out and also find out how to propagate such branch information. git is flexible about how you use it, and if it works, then it works. Another thing I like is that none of the machines is “central”; in fact, I view them all as backing each other up. In particular, I don’t need the external drives for backing up my daily work anymore, they’re only for photos, videos, and things like that.

The only obvious issue is if I edit the same file on 2 different laptops and then sync, then I get merge conflicts, as would be expected. At first this was a problem, but now I generally remember to start a work session by gitfr from my backpack laptop to keep everything sync’d up.