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.
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.
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 .
After creation, Git toolbar buttons appear on the right side of the IDEA toolbar. The checkmark (✓) icon opens the commit dialog.
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.
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 .
On the Dev branch, modify GitTest.java (add a line) and commit.
Switch back to master via the branch popup in the bottom-right corner.
On master, modify the same file differently and commit.
Merge Branches and Resolve Conflicts
Choose Git → Merge . In the dialog, select Dev from the dropdown and click Merge .
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.
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 .
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
