Pull and Merge the Back Office's Work

Your laptop knows about next week’s deals now, but they sit on origin/main, and your main still ends with the deli counter’s hours. As long as that’s true, GitHub keeps refusing the laptop’s push, however politely you ask. The hint from the rejected push already named the way out: git pull.

In this lesson, you’ll pull the back office’s work into your laptop’s main. You’ll tell Git once how to combine two lines of history, finish the merge it makes, and push both issues’ work to GitHub. Start with the command the hint suggested.

Pull the Back Office’s Work

Your main and origin/main have diverged, and the deals have to end up in your main before GitHub accepts anything from the laptop. That’s the job of git pull. It runs a fetch from the branch’s upstream and then integrates what arrived into the branch you’re on. You fetched a minute ago, so the fetch part won’t find anything new this time.

In the laptop’s terminal, in your generic-grocery folder, run it:

Language: Shell
$ git pull
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

Hmm, Git stopped again, but this time it’s asking you a question instead of refusing your work. Anyone with a fresh Git setup meets this message the first time they pull with new commits on both sides. Your commit, your files, and origin/main are exactly as they were. As with errors in JavaScript, the message tells you what went wrong and what to do next.

The first line says why it stopped. Divergent branches explain the “1 and 1” that git status showed you: each side has a commit the other doesn’t. Git can’t only move your main forward to the deals, because then the deli hours would be left behind. It has to combine the two lines, and there’s more than one way to do that, so it wants you to choose.

The hint lists three settings, one for each choice:

  • pull.rebase false merges. Git makes a merge commit that joins your line and GitHub’s, like the merge of main into vite in the last course.

  • pull.rebase true rebases. Git replays your own commits on top of GitHub’s, so the history stays one straight line. Many teams use it. This course leaves it out on purpose, so that’s all you need to know about rebasing for now.

  • pull.ff only only accepts a pull that needs no combining at all. On your laptop right now, it would stop with an error instead of merging.

The documentation of git pull describes all three if you’re curious. This course merges, because a merge keeps both lines exactly as they happened. Set that once for every repository on this computer:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.