Skip to main content
Android Code Studio includes comprehensive Git integration powered by JGit, enabling full version control capabilities directly from your Android device.

Overview

The Git integration provides:
  • Repository initialization and cloning
  • Staging and committing changes
  • Branch management
  • Remote repository operations (push, pull, fetch)
  • Commit history viewing
  • Diff viewing and change tracking
  • .gitignore and .gitattributes support
Git operations are powered by JGit, a pure Java implementation of Git that runs natively on Android.

Getting Started

Initialize a Repository

Create a new Git repository for your project:
1

Open Git Menu

Navigate to Tools > Git or tap the Git icon in the toolbar
2

Initialize Repository

Select “Initialize Repository” to create a new Git repo
3

Set Default Branch

Choose your default branch name (e.g., “main” or “master”)
4

Configure User

Set your Git username and email for commits
# Initialize repository
cd ~/projects/MyApp
git init

# Set user configuration
git config user.name "Your Name"
git config user.email "[email protected]"

Clone a Repository

Clone an existing repository from a remote URL:
1

Select Clone

Choose Git > Clone Repository from the menu
2

Enter Repository URL

Provide the Git repository URL (HTTPS or SSH)
3

Choose Location

Select the local directory for the cloned project
4

Enter Credentials

Provide username and password/token if required
Clone Examples
# HTTPS
https://github.com/username/repository.git

# SSH
[email protected]:username/repository.git
For GitHub, use a Personal Access Token instead of your password for HTTPS authentication.

Making Commits

View Changes

See what files have been modified:
1

Open Git Status

Navigate to Git > Status or view the Git panel
2

Review Changes

View modified, added, deleted, and untracked files
3

Check Diff

Tap on a file to see the detailed diff of changes
Change Types:
  • Modified - Existing files with changes
  • Added - New files staged for commit
  • Deleted - Files removed from the project
  • Untracked - New files not yet added to Git
  • Conflicting - Files with merge conflicts

Stage Changes

Add changes to the staging area:
# Stage a single file
git add path/to/file.java

# Stage multiple files
git add src/MainActivity.java res/layout/activity_main.xml

Create Commits

Commit staged changes to the repository:
1

Stage Your Changes

Ensure all desired changes are staged
2

Write Commit Message

Enter a clear, descriptive commit message
3

Commit

Tap “Commit” to save changes to the repository
Commit Message Best Practices
# Good commit message format:
Add user authentication feature

- Implement login screen
- Add password validation
- Integrate with backend API

# Short messages for simple changes:
Fix typo in MainActivity

Update dependencies to latest versions
Write meaningful commit messages that explain why the change was made, not just what changed.

Branch Management

View Branches

See all available branches in your repository:
List Branches
# View local branches
git branch

# View all branches (local + remote)
git branch -a

Create Branches

Create new branches for features or bug fixes:
1

Open Branch Menu

Navigate to Git > Branches
2

Create New Branch

Select “New Branch” and enter a branch name
3

Switch to Branch

The new branch is automatically checked out
# Create and switch to new branch
git checkout -b feature/new-ui

# Create branch without switching
git branch feature/new-ui

Switch Branches

Move between branches:
Switch Branches
# Switch to existing branch
git checkout main
git checkout feature/new-ui

# Switch to previous branch
git checkout -
Commit or stash your changes before switching branches to avoid losing work.

Delete Branches

Remove branches that are no longer needed:
Delete Branch
# Delete local branch (must not be current branch)
git branch -d feature/completed-feature

# Force delete unmerged branch
git branch -D feature/abandoned-feature

Remote Operations

Add Remote

Connect your local repository to a remote:
# Add remote repository
git remote add origin https://github.com/username/repo.git

# Verify remote
git remote -v

Push Changes

Upload local commits to remote repository:
1

Commit Local Changes

Ensure all changes are committed locally
2

Select Push

Choose Git > Push from the menu
3

Select Branch

Choose the branch to push
4

Enter Credentials

Provide authentication if required
Push Commands
# Push current branch to origin
git push origin main

# Push and set upstream tracking
git push -u origin feature/new-feature

# Push all branches
git push --all origin

Pull Changes

Download and merge changes from remote:
Pull Changes
# Pull from default remote/branch
git pull

# Pull from specific remote/branch
git pull origin main

# Pull and rebase instead of merge
git pull --rebase origin main
Pull operations fetch remote changes and automatically merge them into your current branch.

Fetch Updates

Download remote changes without merging:
Fetch Changes
# Fetch from all remotes
git fetch --all

# Fetch from specific remote
git fetch origin

# View fetched changes
git log HEAD..origin/main

Viewing History

Commit Log

View the commit history of your repository:
# View recent commits
git log

# View compact history
git log --oneline

# View last N commits
git log -10
Commit Information Displayed:
  • Commit hash (full and short)
  • Author name and email
  • Commit date and time
  • Commit message
  • Changed files

File History

View the history of a specific file:
File History
# View commits affecting a file
git log -- path/to/file.java

# View changes to file
git log -p -- path/to/file.java

Advanced Features

Discard Changes

Revert uncommitted changes:
Discard Changes
# Discard changes to specific file
git checkout -- path/to/file.java

# Discard all changes
git checkout -- .
Discarding changes is permanent and cannot be undone!

Unstage Files

Remove files from staging area:
Unstage Files
# Unstage specific file
git reset HEAD path/to/file.java

# Unstage all files
git reset HEAD .

.gitignore Support

The IDE respects .gitignore files:
Common .gitignore Entries
# Build outputs
build/
*.apk
*.aab

# IDE files
.idea/
.gradle/
local.properties

# Generated files
*.class
*.dex
*.log
Add sensitive files like API keys and credentials to .gitignore to prevent accidental commits.

Conflict Resolution

When merge conflicts occur:
1

Identify Conflicts

Git marks files with conflicts as “Conflicting”
2

Open Conflicted File

Edit the file to resolve conflict markers
3

Remove Conflict Markers

Delete <<<<<<<, =======, and >>>>>>> lines
4

Stage Resolved File

Add the resolved file to staging
5

Complete Merge

Commit the merge resolution
Conflict Markers
<<<<<<< HEAD
Your local changes
=======
Incoming changes from remote
>>>>>>> branch-name

Authentication

HTTPS Authentication

For HTTPS remotes:
  • Username: Your GitHub/GitLab username
  • Password: Personal Access Token (PAT)
GitHub: Generate tokens at Settings > Developer settings > Personal access tokensGitLab: Generate tokens at User Settings > Access Tokens

SSH Authentication

SSH support may be limited on Android. Use HTTPS with tokens for best compatibility.

Troubleshooting

Push Rejected

Error
! [rejected] main -> main (non-fast-forward)
Solution:
# Pull remote changes first
git pull origin main

# Resolve any conflicts

# Push again
git push origin main

Authentication Failed

If authentication fails:
  • Verify username and password/token
  • Check token permissions (needs repo access)
  • Try generating a new access token
  • Ensure no typos in repository URL

Repository Not Found

Double-check:
  • Repository URL is correct
  • You have access to the repository
  • Repository exists and is not deleted
  • Network connection is stable

Large File Warnings

Git is not optimized for large binary files. Consider using Git LFS for files over 50MB.

Best Practices

Commit Frequently
  • Make small, focused commits
  • Commit working code, not broken code
  • Write descriptive commit messages
Branch Strategy
  • Use branches for features and fixes
  • Keep main/master branch stable
  • Delete merged branches
Before Pushing
  • Review your changes
  • Test your code
  • Pull latest changes
  • Resolve conflicts locally
Security
  • Never commit secrets or API keys
  • Use .gitignore for sensitive files
  • Review changes before committing

Build docs developers (and LLMs) love