Are you irritated of having too many branches in your repo? This article explains how to work in a thicket of branches and how to cut them down in one shot.
The typical scenario of daily work with Git Flow looks like this: we create a feature branch, work on it and, once the branch is merged, we leave it and we go to the next task. We simply forget or don’t care to remove these development branches from our local repository and we finally find ourselves in a situation with a whole bunch of unnecessary branches in our repo.
We could leave it like that but it is useless to keep a few-month-old branch if it has been merged or is no longer relevant. What’s more, it can impede our work.
Git in Android Studio
Some people use VCS integration in Android Studio and do Git related stuff from IDE. Let’s see how a checkout to another branch looks like.
- Click on the Git tab in the window at the right bottom corner
- Select a wanted branch
- Click Checkout on the submenu
Three mouse clicks. It’s as simple as that.
Really? Having a lot of branches means the results are not so fast. I have seen people scrolling the whole list to find an appropriate branch. But it doesn’t have to be this way.
Android Studio allows us to start typing wherever we are. So after the first step, we can easily type the name of a branch to find the one we are looking for.
Well, why use the mouse?
We can also use shortcut ctrl + v (Mac) and then 7 and start typing. What can you do to avoid typing a lot?
You can add branches to favourites, clicking on a star and limiting the number of displayed branches using Show Only Favorites.
Well, our branches are still there and we don’t need them anymore.
Get rid of them
Let’s go to the terminal. You probably have remote branches that are actually deleted from a remote repository. How to remove them:
Optionally we can use a
--dry-run flag to check what will be pruned before we do it.
You can also remove any local branch that has already been merged into the develop or master.
It is not comfortable to type the whole command every time we want to do this. The solution is to add aliases to ~/.gitconfig
Working with a huge git repository can by a hard task. Yet it’s worth knowing that you can easily clean up you repo a little bit and make your work better.
Also published on Medium.