solve git upload file error [rejected] master -> master (fetch first) error: failed to push some refs to '

created at 10-07-2021 views: 52

I encountered some problems when uploading files with git at the beginning
first question
Upload steps:

git add.
git commit -m "prompt message"
git push origin master


! [rejected] master -> master (fetch first) error: failed to push some refs to '. . . '

This problem occurs because the file in github is not in the local code directory. You can use the following command to merge the code

git pull --rebase origin master

second question

! [remote rejected] master -> master (pre-receive hook declined)

The above error was reported when pushing the code. The method found on the Internet says that the master in the project setting is a protected project, so the developer cannot push it. The solution is to modify the protected setting or create a new branch and push it to your own branch.

Third question

git add .
git push origin master

There is such a problem everything up-to-date


Git commits changes to the cache, and when you want to push, it will not push all the local branches, so this problem occurs. Then we need to create a new branch, commit the changes and then merge the branches.

1. First create a new branch and commit changes

$ git branch newbranch

2. Check whether this command was created successfully

$ git branch

At this time, the terminal will output:


In this way, the creation is successful, the front * represents the current work branch you are in, and then you need to switch the work branch.

3.git checkout newbranch

4. Then submit your changes to the new branch

$ git add.
$ git commit -m "prompt message"

At this point, you can check the submission status with $ git status. If the submission is successful, we will go back to the master branch next, $ git checkout master

5. We merge the changes submitted by the new branch to the main branch

$ git merge newbranch

Merging branches may cause conflicts. This is normal. Although we are new branches that will not cause conflicts, we still record them here. Can use

$ git diff to view the conflicting file, and then make the corresponding modification and submit it again.

6. Our problem is solved, then we can push the code

$ git push -u origin master

7. Finally, friends who create a new branch, don't forget to delete the branch

$ git branch -D newbranch

If you want to keep the branch and just want to delete the merged part, just change the uppercase D to lowercase d.

In summary, I probably encountered these major problems during the upload process. I searched a lot of solutions on the Internet and found that even if the problems encountered are the same, the solutions may not apply to me. Record it and see if there are other solutions and problems later.

created at:10-07-2021
edited at: 10-07-2021: