Live data from Hacker News

Git tips from the trenches

ochronus.com

1–10 of 47 posts

Re: Git tips from the trenches

#2
> $ git branch --merged | xargs git branch -d

  does this actually work? `git branch --merged` for me also 
  returns '* master', which when xarg'd would include the '*'
  and also 'master'. I don't want to delete master, and I
  certainly dont want to delete * if it globs.
EDIT: made this into a code block as I have no idea how to make asterisks display.

Re: Git tips from the trenches

#3
post #2

> $ git branch --merged | xargs git branch -d does this actually work? `git branch --merged` for me also returns '* master', which when xarg'd would include the '*' and also 'master'. I don't want to delete master, and I certainly dont want to delete * if it globs. EDIT : made this into a code block as I have no idea how to make asterisks display.

It'll be fine, git will refuse to delete the branch you're on and the loop will continue:

error: Cannot delete the branch 'master' which you are currently on.

Re: Git tips from the trenches

#4
post #2

> $ git branch --merged | xargs git branch -d does this actually work? `git branch --merged` for me also returns '* master', which when xarg'd would include the '*' and also 'master'. I don't want to delete master, and I certainly dont want to delete * if it globs. EDIT : made this into a code block as I have no idea how to make asterisks display.

Yeah, didn't think about that, could be tricky if you're on another branch. Nice catch!

Re: Git tips from the trenches

#6
I liked this one:

    git blame -w
Ignore the whitespace if a block was [un]indented, attribute to original author instead of person re-indenting due to control structure change around block.

Re: Git tips from the trenches

#8
post #2

> $ git branch --merged | xargs git branch -d does this actually work? `git branch --merged` for me also returns '* master', which when xarg'd would include the '*' and also 'master'. I don't want to delete master, and I certainly dont want to delete * if it globs. EDIT : made this into a code block as I have no idea how to make asterisks display.

[deleted]

Re: Git tips from the trenches

#10
post #2

> $ git branch --merged | xargs git branch -d does this actually work? `git branch --merged` for me also returns '* master', which when xarg'd would include the '*' and also 'master'. I don't want to delete master, and I certainly dont want to delete * if it globs. EDIT : made this into a code block as I have no idea how to make asterisks display.

I have an alias that I have created that prevents the branch you are currently on or master from being deleted.

alias gclean='git remote prune origin; git branch --merged | grep -v -E "(\*|master)" | xargs -n 1 git branch -d'

Post reply on HN