@jwebcat: Oh heh, sorry, I didn't mean you could replace the whole thing with it, I meant you had this:
function git_current_branch() {
git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///'
}
Which could be simplified to use less processes:
function git_current_branch() {
git symbolic-ref --short HEAD 2> /dev/null
}
;)
Also thanks for the tip that that git symbolic-ref
can be used for creating an orphan branch, I've always used git checkout --orphan
for that.
Speaking of orphans, you might find this gist interesting, it's something I made when I had to extract a single file from a repository to its own repository and I didn't want to include the history for other files. Perhaps you even have a better way to do it, I'm extremely interested in learning new things about git as well!
I also use git symbolic-ref
for changing the HEAD of remote --bare
repos (for those that don't know, the branch set as HEAD is used as default when you clone a repo), since you obviously can't git checkout
:
$ git symbolic-ref HEAD refs/heads/my-branch
Nice!
BTW, I think you would achieve the same results with git symbolic-ref --short HEAD
@mlafeldt very nice! It also makes it branch-agnostic! Thanks!
@da-x: seems great! I wonder if you could also add support for interactive mode in the vein of
git add -p
and friends. Maybe you could even (ab)use git itself for the UI.