I have a remote git repository and a local one that i work with. Whenever i do any changes locally, i push them to the remote. Then i sometime do a "git commit" on the remote one to store the changes on the remote files.
I do not edit the remote repository directly at all. I just commit the changes. And i'm a single developer, no one else works on that repos.
Why do i get an error that, from what i know, means that i have to pull first ?
I don't want to pull because the remote repos files are outdated and it will lose my local changes. This is really annoying, why does this happen ? And how can i fix without having to pull or recreate the repository ? (as you can see, this is sort of like a subversion type of version control style here)
EDIT - The error :
To ssh://...
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://...'
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.
Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused. 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://github.com/USERNAME/REPOSITORY.git > !
If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.
At the top of your repository on GitHub.com's Quick Setup page, click to copy the remote repository URL. In the Command prompt, add the URL for the remote repository where your local repository will be pushed. Push the changes in your local repository to GitHub.com.
I have also faced same error and wasted lots of time, Here is final solution.
when use git push origin master then we get error so solution is to force push. so use second option. it worked for me.
git push origin master --force
Here is another option.
git reset --mixed origin/master
git add .
git commit -m "Your message"
git push origin master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With