Git should be integrated into the project.
Check to see if Git is set up.
Navigate to Android Studio > Preferences > Version Control > Git. To ensure that Git is properly configured in Android Studio, click Test.
Allow integration of version control
Assume you've just started a new Android project called MyApplication. Go to VCS > Enable Version Control Integration in Android Studio. If it has previously been integrated with a version control system, this option will be hidden.
Then, as the version control system, select Git.
A default local master branch will be created if VCS is successfully enabled.
To exclude files from Git, add. gitignore.
Two. gitignore files are automatically added when you create a new Android project in Android Studio (one in the project root folder, and the app folder). Git should not contain files such as generated code, binary files (executables, APKs), or local configuration files. Version control should be disabled for those files. Here is the content of my first. gitignore file:
# content of .gitignore *.iml .gradle /local.properties /.idea/* .DS_Store /build /captures .externalNativeBuild .cxx
Changes are staged and committed
The project is complete and ready for use with Git version control. Go to VCS > Commit to stage and commit your changes.
You will be presented with a dialogue in which you can examine all files that will be added, enter commit messages, and commit. You can uncheck any files that you do not want to be part of this commit.
When you click commit, a popup alerts you that you haven't yet configured your username or email address. Because they will be attached to your commit message, you should always configure them.
"Set properties globally" is an option. I recommend that you do not check this because doing so will result in every git project on your local machine having the same username/email. You may want to have separate usernames/emails for side projects and company projects.
All done — the entire project has now been pushed to Git.
Configure Remote Connections
Go to VCS > Git > Remote to add the project to the remote repository.
To add a new remote, click "+," then enter your remote URL in the URL box. Your local project is now linked to your remote Github repository. You can use Bitbucket, Gitlab, or any other repository in addition to Github. Changes are being pushed to the remote. Go to VCS > Git > Push to push your local changes to the remote repository. The "Push Commits" popup shows which commit will be pushed to the remote-tracking branch. You may proceed with the push.
Obtain the Changes from the Remote
To download the most recent remote changes, navigate to VSC > Git > Pull.
The popup "Pull Changes" appears. I won't go into detail about the pull strategy; simply use the default> strategy and perform the pull.
Collaborate with Branches
Some consider Git's branching model to be its defining feature, and it undoubtedly distinguishes Git in the VCS community. In this section, I'll show you how to use branches in Android Studio.
Make a new branch.
Navigate to VCS > Git > Branches.
The phrase "Git Branches" appears. It displays all of the local and remote branches, as well as the "New branch" option.
Click "New Branch" and give it the name "feature branch."
The other branching possibilities
Assume you're standing near the feature branch. When you expand the menu by clicking on the master branch, you will see many options:
Let me explain each of them in turn:
Checkout: The master branch.
Checkout As: check out a new branch from master. Checkout master and rebase feature branch onto it.
Compare with current: commits that exist in master but not in feature, and vice versa.
Show Diff with Working Tree: Display the difference between the master and the current working tree.
Checkout and Rebase onto Current: Current should be rebased on
Rebase Current onto Selected: Rebase master on the feature has been chosen.
Merge into Current: combine the master and a feature.
Rename: change the name of the master branch.
Delete: remove the master branch from the tree.
You will select the best option based on your requirements.
Display Log History
Select VCS > Git > Show History from the menu.
The history of the currently open file will be displayed in Android Studio,
You can view the entire log history by clicking on the "Log" tab.
You can filter the history here by branch, user, and date, making it easier to find the commit you're looking for.
If you have any doubts about how to use Git in android studio. Don’t hesitate to contact us. Airo Global Software will be your digital partner.
E-mail id: [email protected]
Author - Johnson Augustine
Chief Technical Director and Programmer
Founder: Airo Global Software Inc
LinkedIn Profile: www.linkedin.com/in/johnsontaugustine/