branch
git tips
Thursday, December 25th, 2008 | english, utilities | 4 Comments
Git is becoming my main utility for Debian packaging, as I am using it to keep my work on packages I maintain alone or in a team by using git.debian.org facilities. I am not still using tools like TopGit to keep patches, by I also intend to do so in a near future.
What does git give me over svn? Basically two things: branches and having the whole source code at hand. The first is obvious, I can easily create branches to experiment without having to change anything in the way the package is, so if a new upstream release occurs in the time it takes me to implement some change (and that usually happens) I can upload it straight, not affecting my undergoing changes.
Also I appreciate having the whole source code. This could have been also done using svn, but we preferred not to do so, and most packages only have debian dir in their svn repositories. This makes harder work with upstream sources, where they need to be patched. Git provides me the way to have always an upstream source code copy at hand, and the branch power can also be applied to it.
But I wanted to write about a couple of git tips that I found. Seems that they have already appeared on Planet Debian before, but I think that is not a bad idea to remember them (from damog’s blog):
1. Changing into a directory that contains a repo and shows you on PS1 what branch you are standing on:
On .bashrc I have:
GITPS1='$(__git_ps1 ":%s ")'
export PS1=”${GREEN}\w${RS} ${YELLOW}${GITPS1}${RS}\\$ ”
But what I didn’t want to lose was the code that was posted to paste.bin after in a comment someone pointed out that this trick was a bit annoying if your home dir were also a git repo. This is one solution:
__maybe_git_ps1 () {
local BRANCH=”$(__git_ps1 ‘%s’)”
case “$BRANCH” in
master)
# silent
;;
”)
# not a git repo? -> silent
;;
*)
if [ -n "$1" ]; then
printf “$1″ “$BRANCH”
else
printf ” (%s)” “$BRANCH”
fi
;;
esac
}
2. An alias I like to use on repos that are personal for quick tracking:
[alias]
…
log1 = log –pretty=oneline –abbrev-commit
Thanks damog for these tips!

