This page looks best with JavaScript enabled

GitFixPushError

 ·  ☕ 2 min read  ·  🤖 TED LZY

The error message you’re encountering indicates that your local master branch is behind the remote master branch on GitHub. To resolve this issue, you need to update your local branch with the changes from the remote branch before you can push your changes.

Here’s how you can fix it:

Steps to Fix

How to fix:

(base) tedl@Teds-MacBook-Pro public % git push
To https://github.com/Ted-L/Ted-L.github.io.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/Ted-L/Ted-L.github.io.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
(base) tedl@Teds-MacBook-Pro public %

To fix the error you’re encountering when trying to push to your GitHub repository, follow these steps:

Step 1: Fetch the latest changes from the remote repository

First, you need to fetch the latest changes from the remote repository. This will update your local repository with any changes that have been made on GitHub.

1
git fetch origin

Step 2: Merge the changes

Next, you need to merge the changes from the remote master branch into your local master branch. You can do this using the following command:

1
git merge origin/master

If there are no conflicts, the merge will complete successfully. If there are conflicts, you’ll need to resolve them in your files.

Step 3: Push your changes

Once the merge is complete (and conflicts are resolved, if any), you can push your changes to the remote repository:

1
git push origin master

Alternative: Using git pull

Alternatively, you can combine the fetch and merge steps into one command using git pull:

1
git pull origin master

After pulling, if there are no conflicts, you can then push your changes:

1
git push origin master

Summary

  • Fetch the latest changes: git fetch origin
  • Merge the changes: git merge origin/master (or git pull origin master)
  • Push your changes: git push origin master

This should resolve the non-fast-forward error you are facing.

Share on

TED LZY
WRITTEN BY
TED LZY
Programmer