This is the 22nd day of my participation in the August More Text Challenge. For the Nuggets’ August challenge,

[rejected] master -> master (fetch first) error: Failed to push some refs to ‘

When I first started uploading files with Git, I encountered some problems.

Git add. Git commit -m "git push origin masterCopy the code

Error:

! [rejected] master -> master (fetch first) error: failed to push some refs to ' 。。。'
Copy the code

This problem occurs because the readme. md file on Github is not in the local code directory. You can run the following command to merge the code

git pull --rebase origin master
Copy the code

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

As shown in the error in the push code, the method found online is that the master is a protected project in the setting of the project, so the developer cannot push it. The solution is to modify the protected setting, or create a new branch and push it to its own branch

I tried to upload a project to GitLab the day before yesterday, but I failed to upload it after many attempts. The error is as follows:

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

At first, I thought I had the wrong username and password. I tried many times, but the Internet search failed to find a clear result, but I finally found a solution.

The reason why git push does not work is that the branch permission of git push is protected. Only the project administrator or someone assigned by the project administrator with the corresponding permission can push the project. There are two ways to push the project:

1. Turn off protected permissions on the branch where you want to push the content

(1) Enter the Settings of the project

Unprotected Branches Click enter Protected Branches, click Unprotected To change the permission of master branch, i.e. turn off the Protected permission of master

2. Create another branch, push the project to the new branch, and merge the project later

(1) Create a branch

Git branch Specifies the branch nameCopy the code

(2) Switch branches

Git Checkout branch nameCopy the code

(3) Upload the project

Git add. Git commit -m "commit information" git remote add originCopy the code

Nothing to write blog ha ha ha!

Third question

git add .
git push origin master
Copy the code

The problem is everything upto-date

Cause: Git commits changes to the cache, which does not push all local branches. Then we need to create a new branch and commit the changes and merge the branches.

1. Create a new branch to commit changes

 git branch newbranch
Copy the code

2. Check whether the command is created successfully

 git branch
Copy the code

The terminal will output:

newbranch
​
*master
Copy the code

The * in front represents the work branch you are currently in, and the next step is to switch the work branch.

3.git checkout newbranch

4. Then commit your changes to the new branch

Git add. Git commit -mCopy the code

At this point, you can check the submission status. Git Checkout Master: Git Checkout Master

5. We merge the changes committed by the new branch onto the main branch

 git merge newbranch
Copy the code

Merging branches can cause conflicts, which is normal, although our new branch will not cause any conflicts, but it is noted here. You can use

Git diff to see the conflicting files, make the changes and commit again.

6. Now that our problem is solved, we can push the code

git push -u origin master
Copy the code

7. Finally, don’t forget to delete branches

 git branch -D newbranch
Copy the code

If you want to keep the branches and just delete the merged parts you just change the capital D to the lower case D.

To sum up, I probably encountered these major problems in the process of uploading. I searched a lot of solutions online and found that the solutions may not apply to me even if the problems I encountered are the same. Take notes and see if there are other solutions and problems later.