Push and Pull in IntelliJ: Two Developers, One GitHub Repository, a Rejected Push and a Conflict
Jack and Emma share hello-app on GitHub using IntelliJ's Git buttons: a first push, a clone, a pull that fast-forwards, a push that gets rejected, and a conflict on line 3 resolved in the merge window. Then the daily pull and push loop.
What you will learn
- Push, clone, commit and pull with IntelliJ's Git menu and know the git command behind each
- Explain why a push is rejected and fix it with pull, merge, push
- Resolve a conflict in IntelliJ's three-pane merge window
- Follow a daily loop for when to pull and when to push
Before you start
- Git and GitHub Fundamentals: Commits, Branches, Push and Pull
- IntelliJ IDEA installed
The Git basics are covered in Git and GitHub fundamentals: commit, branch, push and pull. This article watches two developers, Jack and Emma, share one project on GitHub using the Git buttons in IntelliJ. We follow every commit as it travels: a push, a clone, a pull, a push that gets rejected, and one conflict.
One shared copy, two private copies
Think of a class project folder. Each student takes a copy home and writes in it. Nobody sees your pages until you hand them in, and you don't see your friends' pages until you pick up a fresh copy. GitHub is the folder at school, git push is handing your pages in, and git pull is picking up the fresh copy.
Jack pushes
Jack has created an empty repository called hello-app on GitHub and has two commits on his laptop. In IntelliJ he chooses Git > Push (Ctrl+Shift+K). The dialog lists exactly the two commits GitHub doesn't have yet, under the line main → origin : main: Jack's main branch goes to GitHub's main branch, and origin is the short name for the GitHub address. A small green New tag says main doesn't exist on GitHub yet.
He clicks Push. IntelliJ says it pushed main to new branch origin/main, and a refresh of GitHub shows both files with two commits. In a terminal this is:
git push -u origin main
Push sends commits, not files. Anything you changed but didn't commit stays on your laptop.
Emma clones
On GitHub, Emma clicks the green Code button, picks HTTPS and copies the address. In IntelliJ she clicks Clone Repository, pastes the URL, picks a folder and clicks Clone. The project opens with Hello.java and the README. That's git clone plus the address.
The commit ids on Emma's laptop are exactly the same as on Jack's. A clone isn't a few files copied over; it's an exact copy with the full history.
Emma commits, then pushes
Emma adds a line to the README on how to run the program; the green bar in the gutter marks new lines. She opens the commit window (Ctrl+K), ticks the file, writes add how to run and clicks Commit. That commit is on her laptop only; GitHub knows nothing about it. Then Git > Push: one commit to send, pushed to origin/main. GitHub now has three commits.
Has Jack's README changed? No. Jack has to ask for it.
Jack pulls
Jack chooses Git > Update Project (Ctrl+T), keeps the first option, merge, and clicks OK. One file updated in one commit, and Emma's line appears in his README. The terminal version:
git pull
Updating ...
Fast-forward
README.md | 2 ++
Pull does two things: it fetches (downloads the new commits) and then merges them with your work. Jack had nothing new of his own, so Git simply moved him forward. That's a fast-forward. In short, pull is fetch plus merge.
Emma pushes first. Jack is rejected.
Now both work at the same time. Jack adds a goodbye line in Hello.java and commits. Emma creates a .gitignore and commits. Different files, and each commit is only on its own laptop.
Emma pushes first. Then Jack clicks Push and gets Push Rejected: the push of current branch main was rejected. In a terminal it says rejected ... (fetch first), with a hint to use git pull before pushing again.
Why? If Git accepted Jack's push, Emma's commit on GitHub would be thrown away, so Git refuses. A rejected push is not an error in your code. It only means someone pushed before you.
Merge, then push again
In the rejection dialog Jack clicks Merge. IntelliJ pulls Emma's commit and creates one extra commit, a merge commit, joining her work and his; the .gitignore appears in his project. The Git log (Alt+9) shows two lines, his commit and hers, joining at the merge commit. He pushes again and it goes through: two commits, his goodbye commit and the merge. The next time Emma pulls, she gets both.
A conflict: the same line, changed twice
Emma changes line 3 of Hello.java to Welcome, Jack, commits and pushes. Jack changes the same line to Hello, team and commits, but forgets to pull first. When he runs Update Project, IntelliJ shows the Conflicts window: Hello.java, modified by you and modified by them. Git can't guess which line should win; that's a human decision.
Inside the file, Git has written both versions between markers:
<<<<<<< HEAD
(Jack's line 3: Hello, team)
=======
(Emma's line 3: Welcome, Jack)
>>>>>>> (Emma's commit id)
Between <<<<<<< HEAD and ======= is Jack's version; between ======= and >>>>>>> is Emma's, labelled with her commit id.
Pick the line, commit, push
Jack clicks Merge... and gets three panes: his version on the left, the server's on the right, and the result in the middle. He keeps both ideas and writes Welcome, team; the top right says all changes have been processed. He clicks Apply (in a terminal, git add Hello.java), commits with the message IntelliJ already filled in (merge branch main), and pushes. When Emma pulls, it's a plain fast-forward for her. Now Jack, GitHub and Emma all have the same nine commits.
Changes on different lines merge by themselves. Only the same line changed by two people needs you.
When to pull, when to push
- When you sit down to work, pull.
- Write code and commit in small steps.
- Before you push, pull again; someone may have pushed meanwhile.
- Run it, to make sure it still works after the pull.
- Push, and share it with the team.
Push when a small piece works (it compiles and runs) and before you stop for the day. Never push code that doesn't compile, because everyone pulls it and the whole team is stuck. And don't sit on your changes for a week: the longer you wait, the bigger the conflicts.
IntelliJ buttons and git commands
| IntelliJ | Shortcut | git | Direction |
|---|---|---|---|
| Clone Repository | git clone | GitHub to you, once | |
| Commit | Ctrl+K | git add + git commit | stays on your laptop |
| Push | Ctrl+Shift+K | git push | you to GitHub |
| Update Project | Ctrl+T | git pull | GitHub to you |
| Git log | Alt+9 | git log | nothing moves |
| Merge after a rejected push | git pull, then git push | both ways |
It's the same Git underneath; IntelliJ runs these commands for you. GitLab and Bitbucket work the same way.
Common mistakes
- Expecting a teammate's change to appear by itself. You only get it when you pull.
- Reading "Push Rejected" as broken code. Pull, merge, then push again.
- Changing the same lines as a teammate without pulling first. That's how most conflicts start.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE
Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)Related posts
Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
Install JDK 25 (Microsoft Build of OpenJDK) with JAVA_HOME, install IntelliJ IDEA, then point a run configuration at the JDK and the main class and run Hello World.
Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
Open IntelliJ's AI Chat, pick Claude Agent (the agent behind Claude Code) or Copilot and a model, ask in plain words for Main.java to print the date and time, review the change, and run it.
Java Hello World with Maven: What the JDK Does and What Maven Adds
javac compiles HelloWorld.java into bytecode and java runs it on the JVM. Maven adds one pom.xml, the same folders in every project and one build command. Then a real Maven Hello World in IntelliJ.
Java Variables, Keywords and Naming Rules
A variable is a labelled jar that holds one value at a time. Four small programs show declaring, reassigning, the names Java accepts, the keywords it reserves, and why daysUntilLaunch beats d.
