Project: A Team Conflict
Pull, fix, push.
Now both teammates change the site title, at the same time. Sam pushes first. Let's see what happens to Alex, and how Alex fixes it.

- Both change the title
- Sam pushes first
- Alex has to fix it
Alex's push is rejected
Alex committed a new title, rename the site, and pushes. Rejected. Sam's commit got there first. So Alex pulls, and Git reports a conflict in index dot HTML.
git log --oneline -n 1 46f6610 (HEAD -> main) Rename the site git push To https://github.com/sam/my-site.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/sam/my-site.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. git pull From https://github.com/sam/my-site f63a17a..f2014f9 main -> origin/main Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
Alex resolves it
Alex talks to Sam, and they agree on a title that combines both ideas. Alex edits the file, removes the markers, adds, commits, and pushes. This time it works.
cat index.html <h1>Our Little Studio: Sam and Alex Build Things</h1> <p>Welcome!</p> <a href="about.html">About</a> git add index.html git commit --no-edit [main cfa0c3f] Merge branch 'main' of https://github.com/sam/my-site git push To https://github.com/sam/my-site.git f2014f9..cfa0c3f main -> main
Sam catches up
Finally, Sam pulls. Sam's copy fast forwards to the merge commit, and the graph shows both titles meeting in Alex's merge. Both teammates now have exactly the same history.
git pull From https://github.com/sam/my-site f2014f9..153d187 main -> origin/main Updating f2014f9..153d187 Fast-forward index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) git log --oneline --graph -n 4 * 153d187 (HEAD -> main, origin/main) Merge branch 'main' of https://github.com/sam/my-site |\ | * f2014f9 New site title * | 46f6610 Rename the site |/ * f63a17a Link to about page
Summary
Rejected push, pull, resolve the conflict together, push. Then everyone pulls. That's real teamwork with Git. Next, keeping a long-running branch up to date.
Key takeaways- Rejected? Pull
- Resolve together
- Everyone pulls