Git:error: src refspec master does not match any.error: failed to push some refs to ‘XXX‘

created at 08-20-2021 views: 100

Git Error

I encountered a pit when using Git in Jenkins today...

Git Error: src refspec master does not match any.error: failed to push some refs to'XXX’

Since I am doing DevOps during this period, I need to use Git in Jenkins to submit code to Github, so I have the above error...

shell script:

#!/bin/bash
git config --local user.email "xxx@xxx.com"
git config --local user.name "KING"
git remote set-url origin https://xxx:xxx@xxx.xxx.xxx/xxx/xxx.git
# git pull origin master
git add deploy/pom.xml
git commit -m "jenkins push code to git"
git push origin master

An error was reported during the submission process:

Git Error:
src refspec master does not match any.
error: failed to push some refs to 'XXX'

Find the error solution:
Reason 1: There is no git repository
Solution 1: Build a local git repository

git init

(I do have a local warehouse...)

Reason 2: No files are added
Solution 2: Use the add command to add files

git add fileName

(I have added a file...)

Reason 3: No commit
Solution 3: Use the commit command to submit files

git commit -m "XXX"

(I have submitted the documents...)

Developers basically don’t make the above three mistakes

#Pull and take a look
git pull origin master #success

Tried it locally, you can also use the Git command to submit the code
What's going on? ? ? ? ? ? Is Jenkins so amazing

solution

There must be something wrong. Review the Git Push method:

#git push <remote name> <name of local branch>: <name of remote library>
git push origin HEAD:master
#git push <remote name> <name of local branch> omit remote branch
git push origin master
#git push <remote name>: <remote library name> Omit the local branch
git push origin :master
#git push omit all
git push

Success after using git push origin HEAD:master...

created at:08-20-2021
edited at: 08-20-2021: