Git push u origin master выдает ошибку

I just started using git with github. I followed their instructions and ran into errors on the last step. I’m checking in an existing directory that isn’t currently source-controlled (project about a week old). Other than that, my use case should be pretty run of the mill.

Here’s what’s happening:

$ 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 'git@github.com:{username}/{projectname}.git'

Github’s instructions:

Global setup:

  Download and install Git
  git config --global user.name "Your Name"
  git config --global user.email {username}@gmail.com

Next steps:

  mkdir projectname
  cd projectname
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:{username}/{projectname}.git
  git push origin master

Ikke's user avatar

Ikke

98.9k23 gold badges96 silver badges120 bronze badges

asked May 5, 2009 at 23:13

sutee's user avatar

7

I was having the same issue and then smacked myself in the head because I hadn’t actually added my project files.

git add -A
git commit -am "message"
git push origin master

Till's user avatar

Till

22.2k4 gold badges58 silver badges89 bronze badges

answered Nov 14, 2009 at 2:17

Joey Green's user avatar

Joey GreenJoey Green

3,0603 gold badges18 silver badges14 bronze badges

2

The error message leads to the conclusion that you do not have a master branch in your local repository. Either push your main development branch (git push origin my-local-master:master which will rename it to master on github) or make a commit first. You can not push a completely empty repository.

answered May 6, 2009 at 6:32

Bombe's user avatar

BombeBombe

81.3k20 gold badges122 silver badges127 bronze badges

3

I had the same issue. I deleted the .git folder then followed the following commands

  1. $ git init
  2. $ git add .
  3. $ git remote add origin git@gitorious.org:project/project.git
  4. $ git commit -m "Initial version"
  5. $ git push origin master

Dan McClain's user avatar

Dan McClain

11.7k9 gold badges47 silver badges67 bronze badges

answered Jun 29, 2011 at 9:55

sugnan prabhu's user avatar

I have same issue . it’s solved my problem .
İf you init your git . you have to do on Terminal

1) git add .

2)git commit -m "first commit"

For send to bitbucket

3) git push -u origin --all # pushes up the repo and its refs for the first time

answered Nov 22, 2013 at 12:01

Erhan Demirci's user avatar

Erhan DemirciErhan Demirci

4,1634 gold badges35 silver badges43 bronze badges

0

I just had the same problem while creating my first Git repository ever. I had a typo in the Git origin remote creation — turns out I didn’t capitalize the name of my repository.

 git remote add origin git@github.com:Odd-engine

First I removed the old remote using

git remote rm origin

Then I recreated the origin, making sure the name of my origin was typed EXACTLY the same way my origin was spelled.

git remote add origin git@github.com:Odd-Engine

No more error! :)

answered Apr 9, 2012 at 22:21

Technohazard's user avatar

I had the same error, as Bombe said I had no local branch named master in my config, although git branch did list a branch named master…

To fix it just add this to your .git/config

[branch "master"]
    remote = origin
    merge = refs/heads/master

Kinda hacky but does the job

answered Aug 13, 2009 at 12:59

make sure you are on a branch, at least in master branch

type:

git branch

you should see:

ubuntu-user:~/git/turmeric-releng$ git branch

* (no branch)
master

then type:

git checkout master

then all your changes will fit in master branch (or the branch u choose)

answered Sep 9, 2011 at 18:22

jose alvarez muguerza's user avatar

error: failed to push some refs to 'git@github.com:{username}/{projectname}.git'

Unless you’re generalizing the error message, it looks like you literally put git@github.com:{username}/{projectname}.git as your remote Git repo. You should fill in {username} with your GitHub username, and {projectname} with your project’s name.

answered Sep 15, 2009 at 22:01

mipadi's user avatar

mipadimipadi

397k89 gold badges523 silver badges479 bronze badges

To actually resolve the issue I used the following command to stage all my files to the commit.

$ git add .
$ git commit -m 'Your message here'
$ git push origin master

The problem I had was that the -u command in git add didn’t actually add the new files and the git add -A command wasn’t supported on my installation of git. Thus as mentioned in this thread the commit I was trying to stage was empty.

answered Jan 29, 2011 at 21:45

Asciant's user avatar

AsciantAsciant

2,1301 gold badge15 silver badges26 bronze badges

1

It looks like this question has a number of answers already, but I’ll weigh in with mine since I haven’t seen any that address the issue I had.

I had this error as well on a brand new github repository. It turns out the user I was pushing from did not have push access. For some reason, this results in an «ERROR: repository not found» error instead of some sort of access error.

Anyway, I hope this helps the poor soul who runs into the same issue.

answered Apr 23, 2012 at 22:20

Tom's user avatar

TomTom

18.6k15 gold badges71 silver badges81 bronze badges

i fixed my problem….

not sure what the problem was but using the gitx interface to commit my staged files, then…

$ git push origin master

worked…

i am having the same problem…

created a new folder added in the bort template files…

$ git commit -m 'first commit'

$ git remote add origin git@github.com:eltonstewart/band-of-strangers.git

$ git push origin master

then i get the same error…

error: src refspec master does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to ‘git@github.com:eltonstewart/band-of-strangers.git’

Arnis Lapsa's user avatar

Arnis Lapsa

45.6k29 gold badges115 silver badges194 bronze badges

answered May 16, 2009 at 5:49

user108060's user avatar

cd  app 

git init 

git status 

touch  test 

git add . 

git commit  -a  -m"message to log " 

git commit  -a  -m "message to log" 

git remote add origin 

 git remote add origin git@git.google.net:cherry 

git push origin master:refs/heads/master

git clone git@git.google.net:cherry test1

Cody Gray - on strike's user avatar

answered Apr 25, 2011 at 6:34

shrikant's user avatar

I had same issue. I had mistakenly created directory in machine in lower case. Once changed the case , the problem solved(but wasted my 1.5 hrs :( )
Check it out your directory name and remote repo name is same.

answered Feb 4, 2012 at 17:59

saathi's user avatar

had the same issue a minute ago and then fixed it

create a repository in github called wordpress…

cd wordpress
git init
git add -A
git commit -am “WordPress 3.1.3″ or any message
git remote add origin git@github.com:{username}/wordpress.git
git push -u origin master

this should work to resolve the refspec issue

Riduidel's user avatar

Riduidel

22k13 gold badges84 silver badges185 bronze badges

answered May 26, 2011 at 20:07

David Chase's user avatar

David ChaseDavid Chase

2,0551 gold badge18 silver badges25 bronze badges

2

This can also happen because github has recently renamed the default branch from «master» to «main» ( https://github.com/github/renaming ), so if you just created a new repository on github use git push origin main instead of git push origin master

answered Dec 18, 2020 at 1:05

mechatroner's user avatar

mechatronermechatroner

1,2621 gold badge17 silver badges25 bronze badges

I mistankly put a space after the — so instead of -m I had — m
Just something to look for.

answered Mar 6, 2010 at 23:20

Brad Madigan's user avatar

I think in older version of git, you should commit at least one file first, and then you can «push origin master» once again.

answered Mar 7, 2010 at 10:33

deddihp's user avatar

great.. its the issue with empty directory only nothing else. I got my issue resolved by creating one binary file in each directory and then added them.

answered Mar 13, 2010 at 21:20

shailesh's user avatar

Initital add & commit worked like a charm. I guess it’s just a matter of understanding Git’s methodology of managing a project within the repository.

After that I’ve managed to push my data straight-away with no hassle.

answered Mar 28, 2011 at 16:28

Matthew Morek's user avatar

Matthew MorekMatthew Morek

2,8262 gold badges17 silver badges13 bronze badges

I just encountered this problem, and it seemed to be caused by my not adding a custom commit message above the default commit message (I figured, why write «initial commit», when it clearly says that very same thing in the Git-generated text below it).

The problem resolved when I removed the .git directory, re-initialized the project directory for Git, re-added the GitHub remote, added all files to the new stage, committed with a personal message above the auto-generated message, and pushed to origin/master.

answered Jun 13, 2014 at 23:46

2540625's user avatar

25406252540625

10.9k8 gold badges49 silver badges57 bronze badges

When you create a repository on Github, It adds a README.md file to the repo and since this file might not be there in your local directory, or perhaps it might have different content git push would fail.
To solve the problem I did:

git pull origin master
git push origin master

This time it worked since I had the README.md file.

answered Sep 6, 2014 at 22:30

Sahil Singh's user avatar

Sahil SinghSahil Singh

3,25239 silver badges62 bronze badges

Before the first commit, try add some file like readme.txt. This will «force» the remote repo create the branch master in case that not exists. It’s worked to me.

answered Oct 10, 2014 at 16:35

Everton Z. P.'s user avatar

This is very old question but for all new people who will end up here like me.
This solution is only for

error: src refspec master does not match any.

error for new repo created

You need to add your

git config user.email "your email"
git config user.name "name"

Only after adding email and name add files to git and commit

git add .
git commit -m "message"

It will work like charm

answered Feb 16, 2015 at 13:03

Pankaj's user avatar

PankajPankaj

1,2421 gold badge9 silver badges21 bronze badges

I have this error too, i put a commit for not push empty project like a lot of people do but doesn’t work

The problem was the ssl, y put the next

git config —system http.sslverify false

And after that everything works fine :)

git push origin master

answered Feb 16, 2016 at 4:48

Eduardo Chávez's user avatar

I was having same problem/error.I was doing git push -u origin master instead i just did git push origin master and it worked.

answered Sep 12, 2016 at 10:54

Ali Akram's user avatar

Ali AkramAli Akram

1994 silver badges12 bronze badges

go to control panel -> manage your credentials and delete github credentials if any.

answered Sep 15, 2019 at 17:38

sudip lahiri's user avatar

Bumping an old thread.

If you have created a repository on Github with a Readme or a .gitignore, you might have to rebase the local master with the remote master. Because, if you are using a project scaffolding tool, like create-app, it creates these files for you, and the remote master needs to be synced with your local before you push.

If you are creating an empty repository on Github, then you can simply push.

answered Jul 7, 2020 at 20:29

Rutwick Gangurde's user avatar

Rutwick GangurdeRutwick Gangurde

4,73411 gold badges52 silver badges86 bronze badges

As some commented above, the problem could be that you do not have email and username or also in my case the problem was that I was trying to push the branch with a different email in the configuration, to check this:

  • git config --list

to modify it (globally):

  • git config --global user.email "email@email.com"

answered Apr 24, 2022 at 20:06

AlezDsGs's user avatar

AlezDsGsAlezDsGs

111 silver badge3 bronze badges

I had the same problem, some of the users have answered this. Before push you must have your first commit.
Now for new users I’ve created a series of simple steps. Before that you need to install git and run in command line:

  • git config user.email «your email»
  • git config user.name «name»

The steps for creating a remote repository (I use dropbox as remote repository):

1. create a directory in Dropbox (or on your remote server)
2. go to the Dropbox dir (remote server dir)
3. type git command: git init --bare
4. on your local drive create your local directory
5. go to local directory
6. type git command: git init
7. add initial files, by typing git command:: git add <filename> 
8. type git command: git commit -a -m "initial version" (if you don't commit you can't do the initial push
9. type git command: git remote add name <path to Dropbox/remote server> 
10. git push name brach (for first commit the branch should be master)

answered Feb 24, 2015 at 8:53

lara's user avatar

I modify my local file. I commit locally and it’s ok. But when i push to github, i have the message that all things are update. Here is the command and its result :

git push origin master

I have the following error message :

Everything up-to-date

Then to see what happen, i run gitK command and i have :

enter image description here

I don’t understand why i am getting this error ? Why i cannot push my code to github ?

I run the command :

git status
On branch dev-branch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

    modified:   deploy/openshift (modified content)

no changes added to commit (use "git add" and/or "git commit -a")

asked Jun 9, 2015 at 22:00

Pracede's user avatar

PracedePracede

4,21616 gold badges63 silver badges110 bronze badges

7

According to your git status message, you are on branch dev-branch not master.

When you git push origin master the last parameter is the branch name. You have commits in a branch named dev-branch not in master, so pushing master does not have any changes to push.

You probably either want to:

git push origin dev-branch

which would create the dev-branch branch on GitHub and push your code there, or..

git checkout master
git merge dev-branch
git push origin master

which would merge your changes from dev-master into master (so master would contain all your commits from dev-branch) then push master to GitHub.

answered Jun 23, 2015 at 1:08

CodingWithSpike's user avatar

CodingWithSpikeCodingWithSpike

42.7k18 gold badges101 silver badges138 bronze badges

You are getting this message beacause you have unstaged changes.

In order to push changes to the server you must follow these steps:

  1. Stage changes : This is when you tell git to track a certain file for changes. You can do this from the command line with : git add -u <filename>
    (the -u flag only adds files that have been updated, thanks to o11c for the tip!)

  2. Commit changes : Once you have added all the files to the stage you need to save them locally with git commit -m "A commit message here"

  3. Push to server : Now run git push origin master

Do everything in one step:

# This adds all updated files in current folder to the stage, 
# then commits with message  and pushes to server


$ git add -u .; git commit -m "[YOUR MESSAGE HERE]"; git push origin master

answered Jun 9, 2015 at 22:05

Jose Llausas's user avatar

Jose LlausasJose Llausas

3,3561 gold badge20 silver badges24 bronze badges

4

Здравствуйте! Изучаю Git, при пуше на сервер вылазит вот такая ошибка, что это значит?

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/...'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Мои действия:
1. Форкнул проект
2. Создал на компе папку, написал git init
3. git clone …
4. git status
5. git add .
6. git status
7. git commit -m «text»
8. git push -u name-repo master
Правильно ли я вообще делаю?

While working with Git, you may have encountered the “error: failed to push some refs to remote git.” This error mainly affects those working on the same codebase as other people. It occurs when changes made to the version control repository have not yet been pushed to the local repository.

This error could arise when working with a team on one project and simultaneously push to a branch. Most times, users get frustrated when they encounter this error. We have listed six ways you can fix this issue.

What Are Some Causes of This Error?

If you get this error message while using Gerrit, it could be due to any of these:

  • Inappropriate change ID in the commit
  • Not committing initial changes before pushing them into the repository.
  • Lack of text files
  • Failure to add files before trying to commit changes
  • Issues with a Git pre-push hook
  • Local repository not in sync with Git repository
  • Incorrect branch name format

How Can I Fix The Error Message Error: Failed To Push Some Refs To Remote Git?

The “error: failed to push some refs into remote Git” can be resolved with some not so technical steps. Pay attention to the hints Git gives you many times; they provide a pointer as to what is wrong and how it could be fixed. You can try the solutions detailed if the hints do not work.

Before you try out the more extensive steps, try this. Run an initial commit and make sure you do not have any uncommitted changes responsible for this error. Once you are done with that, right-click on “remotes” on the side of the source tree and then select “push to origin.” Run the program and check if the error message still pops up.

Solution 1: Ensure You Are Working With The Correct Pair of Repository

This error may be caused by ill-matched repository pair. It means that the local repository name does not match that of the remote Git repository name. To checkmate this issue, always ensure you check and confirm that both repository names match before you pull changes to the remote repository.

If you discover that you spelled the repository name incorrectly, you can remove the local repository using the following steps.

  • Step 1: Enter the command line del /F /S /Q /A .git hit enter, then input the rmdir .git command.
  • Step 2: Correct the name of the local repository (XXXX02->XXXX20). If it is a newly created repository, you can delete it and then recreate the repository correctly. For example, you can change the repository name from the incorrect XXXX02 name to the correct repository name XXXX20.
  • Step 3: Input the command line: Git init. Don’t forget to hit enter once you are done inputting it
  • Step 4: Check if it is mapped. If not, remap with the remote repository. Next, Git remote add origin https://github.com/<username>/XXXX20.git
  • Step 5: Enter Git push –u origin master

Solution 2: Git Pull

Before pushing new changes into the remote Git, we need pull. First, you must be able to distinguish between git push and git pull. Pushing carries the new commit history from the local repository to GitHub. Git pull, on the other hand, collects changes from your GitHub repository and adds them to your local repository.

It combines Git fetch and Git merges in one smooth command, effectively taking small changes from your remote repository and integrating them into your local branch. 

The following steps will help you take care of the error using the Git Pull. 

  • Step 1: Git pull –rebase origin [master | main | other branch name]
  • Step 2: Git push origin[master | main | other branch name] Career Karma

If doing this fails to fix the error, please try the next solution

Solution 3: Git Push

As stated earlier, push involves the transfer of recent changes from the local repository to GitHub. If you run push and get this output or one similar to the one below,

To [email protected]:shabbir-s-test.git

! [rejected] your-branch -> your-branch (non-fast-forward) Assembla Help Center

It means that someone else has pushed the commit to the same branch you are pushing yours to. 

To fix this error, run:

  • Step 1: Git pull origin <your-branch>
  • Step 2: Git push origin <your-branch>

Alternatively, you can try this simple yet powerful solution.

  • Step 1: Git pull –rebase origin master.
  • Step 2: Git push origin master. Lucid Blog

Remember to make a commit first before starting these steps. After the commit, you can now push.

Solution 4: Try to Push

One common reason for the error: failed to push some refs into Git repository, is the failure to follow through with a push. If, for example, you commit but fail to push fast enough, someone else could beat you to it, effectively preventing you from pushing. You may have noticed that while you are still delaying to push, another collaborator commits and pushes. 

The solution to this is to push your work first often and not go dark and work offline for long periods. It is better for the project when you commit, push, and integrate more often. This frequent push makes each integration smaller, less cumbersome, and less prone to error. However, to avoid Git merges, you must push only works that are ready to be shared.

Solution 5: Use Branches

Your early experiences working with yourself and others in master should provide you with an in-depth understanding of why many Git users eventually start to make use of branches. Branches generally provide explicit workflows that can be used to integrate different lines of work as you please. Moving to branches is nicer than trying to perform a tricky rebase or merge while panicked and frustrated. Happy Git

Solution 6: Check Your Working Directory

You may sometimes see the error: failed to push some refs into Git repository message because of some incompatibility between your Git history and GitHub. It means that your history on the local Git repository and the GitHub remote has diverged. 

If this is the case, we advise that you get more information on the situation. You can find out more about the problem using your Git client, Git status, or visiting your GitHub remote history in the browser. These tools will help you identify the missing works responsible for the incompatibility. Try the solution below to fix this issue.

  • Step 1: Input the command Git pull, then hit enter.
  • Step 2: Next, input this command git push. Do not forget to press enter once the command has been inputted.
  • Step 3: Do the force push directly to the remote server.
  • Step 4: Input the following command git push –force

Alternatively, you can use this method. Just input the command below to get all the options related to push: git push –help.

A clear example of this discrepancy in histories has been given below.

If what you have on the GitHub history is A — B – C, and what you have on your local repository history is A — B – D, you may witness this error message. You will be unable to merge on your GitHub history when you push because of this discrepancy. Rather, you have to pull the commit C and integrate it into your D before you can push again. 

One reason you may be seeing this error is missing a local code. If the master branch possesses a code that is not included locally, it tries to prevent you from conflicts by preventing you from pushing further changes. 

To solve this issue, we advise that you pull all the changes made to your local repository. Entering the command line: Git pull origin master –allow-unrelated-histories helps fix this issue. Once the code has been inputted, you will have all the code available on the master branch. Stackoverflow

Note: Exercise caution while pulling the codes from the remote branch. Any mistake may result in the compromise of all the changes made locally. Ensure you save all changes made or create a separate local branch to pull the original master branch. This way, you won’t mess up the changes you have made.

Conclusion

Encountering the “error: failed to push some refs to remote Git repository” message can be frustrating. This error can arise due to numerous reasons: a new commit is pushed into the repository while still working locally. We advise that you add files before trying to commit changes and check that the repository names match. You can fix this error with the solutions provided in this article.

Error: failed to push some refs to – How to Fix in Git

When collaborating with other developers using Git, you might encounter the error: failed to push some refs to [remote repo] error.

This error mainly occurs when you attempt to push your local changes to GitHub while the local repository (repo) has not yet been updated with any changes made in the remote repo.

So Git is trying to tell you to update the local repo with the current changes in the remote before pushing your own changes. This is necessary so that you don’t override the changes made by others.

We’ll be discussing two possible ways of fixing this error in the sections that follow.

We can fix the error: failed to push some refs to [remote repo] error in Git using the  git pull origin [branch] or git pull --rebase origin [branch] commands. In most cases, the latter fixes the error.

Let’s go over how you can use the commands above.

How to Fix error: failed to push some refs to Error in Git Using git pull

To send a pull request means to «fetch» new changes made to the remote repo and merge them with the local repo.

Once the merging is done, you can then push your own code changes to GitHub.

In our case, we’re trying to get rid of the error: failed to push some refs to [remote repo] error by sending a pull request.

Here’s how you can do that:

git pull origin main

If you’re working with a different branch, then you’d have to replace main in the example above with the name of your branch.

Just keep in mind that there are chances of failure when using this command to sync your remote and local repos to get rid of the error. If the request succeeds, then go on and run the command below to push your own changes:

git push -u origin main

If the error persists, you’ll get an error that says: fatal: refusing to merge unrelated histories. In that case, use the solution in the next section.

How to Fix error: failed to push some refs to Error in Git Using git pull --rebase

The git pull --rebase  command is helpful in situations where your local branch is a commit behind the remote branch.

To fix the error, go on and run following commands:

git pull --rebase origin main

git push -u origin main 

If the first command above runs successfully, you should get a response that says: Successfully rebased and updated refs/heads/main.

The second command pushes your local repo’s current state to the remote branch.

Summary

In this article, we talked about the error: failed to push some refs to [remote repo] error.

This error occurs when you attempt to push your local changes to the remote repo without updating your local repo with new changes made to the remote repo.

We discussed two commands that you can use to fix the error: the git pull origin [branch] and git pull --rebase origin [branch] commands.

I hope this helps you fix the error.

Happy coding!



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Возможно, вам также будет интересно:

  • Gimp ошибка при открытии файла psd неподдерживаемая цветовая модель cmyk
  • Gimbal rotation blocking protection ошибка
  • Gimbal motor load too large ошибка mavic pro
  • Gilgen автоматические двери коды ошибок 105
  • Gilgen door systems ошибки e 2000

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии