How to: Merge, Push, Pull, Create a New Branch, and More in Android Studio

Betül Necanlı
3 min readDec 23, 2024

--

In this article we’ll demonstrate how to perform these tasks using both Android Studio’s graphical user interface (GUI) and the terminal.

For a step-by-step walkthrough, check out my YouTube video accompanying this article. Learn visually how to merge, push, pull, and create branches with ease! 👇

Don’t forget to subscribe ❤️

1. Cloning a Repository

Using Android Studio

  1. Open Android Studio and go to File > New > Project from Version Control.
  2. Enter the repository URL and choose a directory to clone the project.
  3. Click Clone.

Using Terminal

✍🏻 Use the cd command to navigate to the directory where you want to clone the repository.

$ git clone <repository-url>

2. Creating a New Branch

Using Android Studio

  1. Open the Git tool window (View > Tool Windows > Git).
  2. Click on the Branch dropdown at the bottom-right corner.
  3. Select New Branch.
  4. Enter a branch name and click OK.

Using Terminal

$ git branch <new-branch-name>
$ git checkout <new-branch-name>

or

$ git checkout -b <new-branch-name>

3. Pulling Changes from the Remote Repository

Using Android Studio

  1. Open the Git menu (VCS > Git).
  2. Select Pull.
  3. In the dialog box, confirm the remote and branch, then click Pull.

💞I write these articles to help fellow developers. If you found this useful and want to support my work, you can do so here: Buy Me a Coffee ☕

Using Terminal

$ git pull origin <branch-name>

✍🏻 Take Notes: Pull vs Update Project ✍🏻

4. Making Changes and Committing

Using Android Studio

  1. Make your changes in the code.
  2. Open the Commit dialog (Ctrl+K / Command+K).
  3. Select the files to commit, write a commit message, and click Commit

Using Terminal

$ git add .
$ git commit -m "Your commit message"

5. Pushing Changes to the Remote Repository

Using Android Studio

  1. Open the Git menu (VCS > Git).
  2. Select Push.
  3. In the dialog box, confirm the branch and click Push.

Using Terminal

$ git push origin <branch-name>

6. Merging Branches

Using Android Studio

  1. Open the Git tool window.
  2. Click the Branch dropdown and select Merge Branches.
  3. Choose the branch you want to merge into the current branch and click Merge.

Using Terminal

$ git checkout <target-branch>
$ git merge <source-branch>

7. Handling Merge Conflicts

Using Android Studio

  1. If a conflict occurs, Android Studio will highlight the conflicting files.
  2. Open the file and use the conflict resolution tool to select changes.
  3. Once resolved, commit the changes.

Using Terminal

  1. Open the conflicting files and manually resolve conflicts.
  2. After resolving, stage the files:
$ git add <file>

3. Commit the resolved changes:

$ git commit

8. Checking the Git History

Using Android Studio

  1. Open the Git tool window.
  2. Go to the Log tab to view commit history.

Using Terminal

$ git log

9. Deleting a Branch

Using Android Studio

  1. Open the Git tool window.
  2. Click the Branch dropdown and select Delete Branch.
  3. Choose the branch to delete and confirm.

Using Terminal

For a local branch:

$ git branch -d <branch-name>

For a remote branch:

$ git push origin --delete <branch-name>

Tips for Using Git Effectively

  • Always pull the latest changes before starting work.
  • Write meaningful commit messages.
  • Use branches to separate features and bug fixes.
  • Regularly push changes to avoid losing work.

--

--

Betül Necanlı
Betül Necanlı

Written by Betül Necanlı

🎥Youtube : https://www.youtube.com/@betulnecanli ✍🏻 Android, Kotlin, Compose, DSA, Math etc.

No responses yet