Git Push Error: error: failed to push some refs… hint: Updates were rejected because the remote…

1. The questions are as follows:

[email protected]:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git push -u origin main
Username for '': echigh
Password for 'https://[email protected]':
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to ''
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

2. The reason is that the remote warehouse has been changed and does not match any local commit version

Reference: [status question] why can’t you push it up sometimes… – learn git for yourself

3. Solution:

1) Merge remote changes with git pull before git push

2) Directly use git push – F to forcibly overwrite the remote warehouse. Anyway, I dare not

4. So I did this:

[email protected]:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git pull
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 21 (delta 13), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (21/21), 5.03 KiB | 66.00 KiB/s, done.
   c6d3d5e..e50b1bc  main       -> origin/main
Merge made by the 'recursive' strategy. | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644

Then push:

[email protected]:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git push
Username for '': echigh
Password for 'https://[email protected]':
Enumerating objects: 44, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (38/38), done.
Writing objects: 100% (38/38), 3.16 MiB | 994.00 KiB/s, done.
Total 38 (delta 19), reused 0 (delta 0)
remote: Resolving deltas: 100% (19/19), completed with 2 local objects.
   e50b1bc..b7684a5  main -> main

Read More: