Version Control with Git in FTC Android Studio Projects

What is Version Control?

Version control is a system that tracks changes to your code over time. It lets you save your work, collaborate with teammates, and revert to previous versions if something goes wrong.

Installing Git and GitHub Desktop

Before you can use version control, you need to install Git and optionally GitHub Desktop. Git is the core version control system, while GitHub Desktop provides a user-friendly interface for Git operations.

Downloading and Installing Git

Git is the foundation of version control. Download it from the official website and follow the installation wizard.

Download Git: Git Official Downloads
Installation Guide: Git Installation Documentation

During installation, use the default settings unless your team has specific requirements. After installation, you can verify Git is installed by opening a terminal and typing git --version.

Installing GitHub Desktop (Optional)

GitHub Desktop provides a graphical interface for Git, making it easier for beginners to use version control. It's especially helpful for teams new to Git.

Download GitHub Desktop: GitHub Desktop Official Site
Getting Started Guide: GitHub Desktop Documentation

After installing GitHub Desktop, you'll need to sign in with your GitHub account to access your repositories.

Setting Up Your GitHub Account

To collaborate with your team, you'll need a GitHub account. Create one at GitHub - Sign Up. Once you have an account, you can create repositories, join your team's organization, and start collaborating on code.

For FTC teams, it's common to have a team organization on GitHub where all team members can access the robot code repository.

Why Use Git?

Git is a popular version control system used by developers worldwide. It makes it easy to share code, review changes, and collaborate with your team. For new teams, we recommend creating an organization in GitHub to host all of your team's code, so you can store previous seasons' code, share code with other teams and help new members get started. For more information on creating organizations in GitHub, see GitHub's documentation on creating organizations.

Basic Git Workflow

The core Git workflow involves cloning a repository, making changes, staging them, committing, and pushing to a remote server. Here are the main steps:

Cloning a Repository

git clone https://github.com/your-team/ftc-robot-code.git

Adding and Committing Changes

git add .
git commit -m "Describe your changes"

Pushing and Pulling

git push
git pull

Branching and Merging

Branches let you work on new features or bug fixes without affecting the main code. Merging brings changes from one branch into another.

Learn more: Git Branch Guide

Creating and Switching Branches

git branch new-feature
git checkout new-feature

Merging Branches

git checkout main
git merge new-feature

Resolving Merge Conflicts

Sometimes, two people change the same part of a file. Git will ask you to resolve the conflict. Open the file, look for conflict markers, and decide which changes to keep.

Learn more: Git Merge Guide

Best Practices for FTC Teams

- Commit often with clear messages.
- Use branches for new features.
- Pull before you push to avoid conflicts.
- Never commit sensitive information.
- Review code before merging.

Practice Exercise

Try the basic Git workflow on your FTC project.

  • Clone your team's repository.
  • Create a new branch and make a small change.
  • Commit and push your change.
  • Open a pull request on GitHub.

Open full interactive app