{"meta":{"title":"Dealing with non-fast-forward errors","intro":"Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused.","product":"Get started","breadcrumbs":[{"href":"/en/get-started","title":"Get started"},{"href":"/en/get-started/using-git","title":"Using Git"},{"href":"/en/get-started/using-git/dealing-with-non-fast-forward-errors","title":"Non-fast-forward error"}],"documentType":"article"},"body":"# Dealing with non-fast-forward errors\n\nSometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused.\n\nIf another person has pushed to the same branch as you, Git won't be able to push your changes:\n\n```shell\n$ git push origin main\n> To https://github.com/USERNAME/REPOSITORY.git\n>  ! [rejected]        main -> main (non-fast-forward)\n> error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'\n> To prevent you from losing history, non-fast-forward updates were rejected\n> Merge the remote changes (e.g. 'git pull') before pushing again. See the\n> 'Note about fast-forwards' section of 'git push --help' for details.\n```\n\nYou can fix this by [fetching and merging](/en/get-started/using-git/getting-changes-from-a-remote-repository) the changes made on the remote branch with the changes that you have made locally:\n\n```shell\n$ git fetch origin\n# Fetches updates made to an online repository\n$ git merge origin YOUR_BRANCH_NAME\n# Merges updates made online with your local work\n```\n\nOr, you can simply use `git pull` to perform both commands at once:\n\n```shell\n$ git pull origin YOUR_BRANCH_NAME\n# Grabs online updates and merges them with your local work\n```"}