Part 1: Setup

Go forward, or back in time, with Git.

Have you ever accidentally deleted code? Do you wish you could go back in time to recover that Kotlin class you deleted because you thought it wasn't being used?

If you've ever lost code, you'll be thankful to know that Git can save your project every hour so that you can go back last week to see that Kotlin class.

I use Git all day long and it has helped a lot. I probably make a commit -- a copy of your project -- every 20 minutes. I also create a new branch for all features I add or bugs I fix.

Git is open source and freely available. On Windows, download from the git website. On Mac, Xcode should install git. On Ubuntu, install with apt install git.

If I'm working on adding a new screen to the app, I'll first create a new branch called add-login-screen. If in an hour I make a mistake, I can always go back to this add-login-screen version of the Android Studio project.

After 2 hours I finish creating the login screen, and we can merge add-login-screen branch into the master branch. It's possible to have multiple branches of a project. At work, I have about 10 different branches. For example, here are some of the branches:

  • master
  • fix-bug-492
  • add-login-screen
  • fix-recyclerview
  • feature-big-red-button

After adding the big red button to the app, I can combine feature-big-red-button into master. Think of each branch as a separate Android Studio project. It takes 2 seconds to switch from branch to branch.

One of the advantages of using Git is that multiple people can be working on the app at the same time. If Jacob is working on fix-bug-492, Brad is working on add-login-screen and I'm working on fix-recyclerview, at the end of the day we can combine all of our branches into a single branch, master.

Part 2: Your First Commit

More Tutorials

Build an Android Ecommerce App in Kotlin - Part 21

Build an Android Ecommerce App in Kotlin - Part 20

Build an Android Ecommerce App in Kotlin - Part 19