Operations 8 min read

Master Git in IntelliJ IDEA: Local Repo Setup, Branching & Conflict Resolution

This tutorial walks through configuring Git in IntelliJ IDEA, creating a local repository, and performing branch operations including creation, merging, conflict resolution, and deletion using a sample Java project with step-by-step UI guidance and screenshots.

Java Captain
Java Captain
Java Captain
Master Git in IntelliJ IDEA: Local Repo Setup, Branching & Conflict Resolution

Configure IDEA Git Integration

After installing IntelliJ IDEA and Git, open or create a project. Navigate to File → Settings (or Preferences on macOS). In the settings dialog, select Version Control → Git . The path to git.exe is auto-detected; if not, specify it manually. Click Test to verify the Git version, then click OK to save.

image
image

Create a Local Git Repository

Create a Java console project named IdeaDemo with a module GitDemo. From the main menu, choose VCS → Create Git Repository . In the dialog, select the project root folder (not the module folder) so Git manages the entire project. Click OK .

image
image
image
image

After creation, Git toolbar buttons appear on the right side of the IDEA toolbar. The checkmark (✓) icon opens the commit dialog.

image
image

In the commit dialog, group by Directory and Module for clarity. Select only source code files for the initial commit; exclude configuration files and compiled output.

image
image
image
image

Branch Operations: Create, Merge, Resolve Conflicts, Delete

Create and Switch Branches

Choose Git → New Branch . Enter branch name Dev and check Checkout branch . Click OK .

image
image
image
image

On the Dev branch, modify GitTest.java (add a line) and commit.

image
image

Switch back to master via the branch popup in the bottom-right corner.

image
image

On master, modify the same file differently and commit.

image
image

Merge Branches and Resolve Conflicts

Choose Git → Merge . In the dialog, select Dev from the dropdown and click Merge .

image
image
image
image

A conflict occurs in

GitTest.java</strong>. IDEA lists the conflicting file. Click the <strong>Merge</strong> button to open the visual merge tool.</p><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/zde386CYzHZcvxPnZlEovazdEm4cKlelgL5vDmL4lJ3SCCibo5fVds1oO3JILv9pTZICdkBzOpK7Fbq9U5jFLa4TtrLzRibAtvibDmjSav7aKE/640?wx_fmt=png&from=appmsg" alt="image"/><p>The merge tool shows <code>master

(left), Dev (right), and the merged result (center). Use the arrow buttons to accept changes from both sides.

image
image
image
image

Click Apply to finalize the merge and auto-commit to master.

Delete the Obsolete Branch

Click the branch name ( master) in the bottom-right corner, select Dev from the list, and choose Delete .

image
image

This completes the core Git workflow in IntelliJ IDEA: local repository setup, branching, merging with conflict resolution, and branch cleanup. The same principles apply to other IDEs and Git clients.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Gitconflict resolutionIntelliJ IDEAtutorialversion controlbranchingmerginglocal repository
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.