← Back to Upcase

Git branch names list is very long


(Kim Khan) #1
  1. The git branch command shows all the branches I have created once they are merged into production can they removed to not appear when git branch is used. I am thinking a year from now that list will be very long.

  2. I have very long branch names. Is there autocomplete for branch names?


(Curt) #2

Hi, not sure if this is what you want for question 1 or not, but you can use “git branch -d branch_name” to delete a branch. I do that from my master branch once I have merged. However, if your question is how to remove the branch from the “git branch” output (without deleting it) I don’t know the answer.


(Kim Khan) #3

Yes, I wanted to know how to remove the branch from the “git branch” output (without deleting it).

If you delete the branch what happens if you need to rollback those changes? Is it possible to rollback changes after it has been merged to master?

Thanks for your reply.


(Curt) #4

I can comment on how I’d do it using bash terminal. If you know the names of the branches you want to suppress in the output you could do something like this at the command line:

$ git branch | grep -v --file=branch_list.txt

Where branch_list.txt is a file with the names you want to suppress, one branch name per line. You could make that command into an alias so you don’t have to type the command each time.

$ alias gitbranch="git branch | grep -v --file=branch_list.txt"

And then put that in your .bashrc file (may be a slightly different name on your system) so the alias loads automatically and will be available for you anytime you launch terminal.

For your other question about rollbacks, I thought that once you merge you are still able to revert to previous commits. But I have a fuzzy understanding of how you’d do that in all situations, and what the exact limitations are. So you’ll need to check that out further. I’d start here for ideas and see where that leads:

$ git help revert
$ git help reset
$ git help reflog

(Jon Seidel) #5

@kimkan Yes, there is autocomplete on branch names, and it works just like bash autocomplete: to finish the name, or again to show a list of multiple matches.


(Kim Khan) #6

Thank JESii. What is the command for branch name autocomplete? Or do you know where I can find the instructions on how to get this to work on my system? I am using Mac OS X.


(Kim Khan) #7

Thank you cs7. I will try your suggestions. This may be exactly what I was looking for!!


(Jon Seidel) #8

@kimkhan… Check out this link. It’s aimed at Mac OSx users.


(Kim Khan) #9

I tried this link and it didn’t work for my Mac OS X environment.

I found these instructions for installing autocomplete script using homebrew and they are not working either. Autocomplete with homebrew install


(Kim Khan) #10

The instructions from the “Autocomplete with homebrew install” link did work I just needed to start a new terminal.

THANKS!!!