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

1. The questions are as follows:

echigh@huangchenggong:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git push -u origin main
Username for 'https://github.com': echigh
Password for 'https://[email protected]':
To https://github.com/echigh/withdraw_frontbytes_of_file.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/echigh/withdraw_frontbytes_of_file.git'
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:

echigh@huangchenggong:/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.
From https://github.com/echigh/withdraw_frontbytes_of_file
   c6d3d5e..e50b1bc  main       -> origin/main
Merge made by the 'recursive' strategy.
 README.md | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 README.md

Then push:

echigh@huangchenggong:/mnt/e/work/workspace/withdraw_validdata_from_file/withdraw$ git push
Username for 'https://github.com': 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.
To https://github.com/echigh/withdraw_frontbytes_of_file.git
   e50b1bc..b7684a5  main -> main

Read More: