1
$ git branch --merged

Produces the following output

  staging
  fix-bug-260
  new-featrue
  hotfix

However if I try and script it using

for branch in $(git branch --merged)
  do 
    git branch -d $branch
  done

I get the following output

Deleted branch staging (was a041124).
Deleted branch fix-bug-260 (was b50b2a1).
Deleted branch new-feature (was ca8e106).
Deleted branch hotfix (was ge9a2j4).
error: branch 'Gemfile' not found.
error: branch 'Gemfile.lock' not found.
error: branch 'Procfile' not found.
error: branch 'Procfile.dev' not found.
error: branch 'Procfile.deve' not found.
error: branch 'README.md' not found.
error: branch 'Rakefile' not found.
error: branch 'app' not found.
error: branch 'bin' not found.
error: branch 'config' not found.
error: branch 'config.ru' not found.
error: branch 'coverage' not found.
error: branch 'data' not found.
error: branch 'db' not found.
error: branch 'doc' not found.
error: branch 'fixtures' not found.
error: branch 'lib' not found.
error: branch 'log' not found.
error: branch 'public' not found.
error: branch 'script' not found.
error: branch 'test' not found.
error: branch 'tmp' not found.
error: branch 'vendor' not found.

The script still works to clean up branches, but I'm not a fan of all the errors

OneChillDude
  • 7,856
  • 10
  • 40
  • 79
  • Does the output of `git branch --merged` actually look like that, or does one of the branches have a star before it? –  Jul 29 '14 at 19:23

1 Answers1

1

The output of git branch --merged includes a *, as your current branch is guaranteed to be merged into itself. That's a shell wild card, and it's being expanded to include all the files in the working directory.

user229044
  • 232,980
  • 40
  • 330
  • 338