[Solved-5 Solutions] src refspec master does not match any when pushing commits in git - git



Error Description:

    • It happens when we try to checkout/clone the new repository from local machine
    $ mkdir carboncake
    $ cd carboncake
    $ git init 
    $ touch a_text_file.txt 
    $ git add a_text_file.txt 
    $ git remote add origin gitosis@myserver.net:repositories/carboncake.git
    $ git push origin master
    
    error: src refspec master does not match any.
    fatal: The remote end hung up unexpectedly
    error: failed to push some refs to 'gitosis@myserver.net:repositories/carboncake.git'
    
    

    Solution 1:

      You've created a new repository and added some files to the index, However you haven't created your first commit yet:

       git add a_text_file.txt 
      

      We do that,

       git commit -m "Initial commit."
      

        Solution 2:

          • The origin has no master branch,when you clone an empty git repository, So the first time you have a commit to push:
          git push origin master
          
          • It will create a new master branch for you.
          • If this didn't fix your issue then it is an gitolite-related issue:
          • An example conf file that came with your gitolite. It looks like below code:
          repo    phonegap                                                                                                                                                                           
              RW+     =   myusername otherusername                                                                                                                                               
          
          repo    gitolite-admin                                                                                                                                                                         
              RW+     =   myusername                                                                                                                                                               
          
          • Make sure you're setting your conf file correctly.
          • Gitolite actually replaces the gitolite user's account with a modified shell that doesn't accept interactive terminal sessions. You can see if gitolite is working by trying to ssh into your box using the gitolite user account.
          • Whether it knows who you are it will say something like "Hi XYZ, you have access to the following repositories: X, Y, Z" and then close the connection. If it doesn't know you, it will close the connection.
          • Finally, after your first git push failed on your local machine you should never resort to creating the repo manually on the server.First we need to know why your git push failed .There will be more confusion when you don't use gitolite exclusively.

          Solution 3:

            • While adding an empty directory. Git doesn't allow to push empty directory. Here is a simple solution. Create the file .gitkeep inside of directory you want to push to remote and commit the "empty" directory from the command line:
            touch your-directory/.gitkeep
            git add your-directory/.gitkeep
            git commit -m "Add empty directory"
            


            Related Searches to src refspec master does not match any when pushing commits in git