Category: Blog, Android, Development

Android Studio and Git Branches – How to Simplify Your Work

Are you irritated by 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.

Android Studio and Git branches

The story

Android Studio and Git branches

The typical scenario of daily work on Android app developement 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.

    1. Click on the Git tab in the window at the right bottom corner
    2. Select a wanted branch
    3. Click Checkout on the submenu

Three mouse clicks. It’s as simple as that.

Android Studio and Git Branches

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.

Facilitate work

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?

Android Studio and Git Branches

We can also use shortcut ctrl + v (Mac) and thenand 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.

Use aliases

It is not comfortable to type the whole command every time we want to do this. The solution is to add aliases to ~/.gitconfig

Conclusion

Working with a huge git repository can by a hard task. Yet it’s worth knowing that you can easily clean up your repo a little bit and make your work better. I hope it will be helpful in your app development process.