Solve Git error error: failed to push some refs to 'https://*****.git'

1. Error description

  Appears when uploading after creating a warehouse giton ! [rejected] main -> main (fetch first), error: failed to push some refs to *****.

insert image description here

2. The cause of the error

  When we create a warehouse, we will check the Add READMEfile . This operation automatically creates a READMEfile and configures to add the ignore file. When you click to create a warehouse, the system will automatically make an initial submission for us. At this time, the empty warehouse will have a README.mdreadme . At this point, we will associate the remote library with the local. Both ends now have content, and there is no connection between the two contents. When we push the local content to the remote end or pull the content from the remote end, there is no connection. The tracked history causes the push or pull to fail. At this time, the above error gitwill be reported.

insert image description here

3. Solutions

  • <1> First, backup the local code to another directory ( gitnot the directory);
  • <2> Delete the files in the local directory to be pushed, except .gitthe directory ;
  • <3> Use the command git pull --rebase origin mainto synchronize the remote content to the local;
  • <4> Copy the backup code back to the current directory to be pushed;
  • <5> Regularly push your code, git add .;
  • <6> git commit -m "Init Commit"
  • <7> git push -u origin main

At this time, you will find that the code will be pushed to the remote library normally.
[注]:第一步一定要备份代码,否则可能会在拉取的时候删除你辛辛苦苦写好的代码。

insert image description here

#over

Guess you like

Origin blog.csdn.net/qq_36393978/article/details/129839510