1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/content/get-started/using-git/dealing-with-non-fast-forward-errors.md
2024-02-09 12:06:24 +00:00

1.7 KiB

title, intro, redirect_from, versions, shortTitle
title intro redirect_from versions shortTitle
Dealing with non-fast-forward errors Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused.
/articles/dealing-with-non-fast-forward-errors
/github/using-git/dealing-with-non-fast-forward-errors
/github/getting-started-with-github/dealing-with-non-fast-forward-errors
/github/getting-started-with-github/using-git/dealing-with-non-fast-forward-errors
fpt ghes ghec
* * *
Non-fast-forward error

If another person has pushed to the same branch as you, Git won't be able to push your changes:

$ git push origin main
> To https://{% data variables.command_line.codeblock %}/USERNAME/REPOSITORY.git
>  ! [rejected]        main -> main (non-fast-forward)
> error: failed to push some refs to 'https://{% data variables.command_line.codeblock %}/USERNAME/REPOSITORY.git'
> To prevent you from losing history, non-fast-forward updates were rejected
> Merge the remote changes (e.g. 'git pull') before pushing again.  See the
> 'Note about fast-forwards' section of 'git push --help' for details.

You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:

$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work

Or, you can simply use git pull to perform both commands at once:

$ git pull origin YOUR_BRANCH_NAME
# Grabs online updates and merges them with your local work