Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push origin master does not work

Tags:

git

github

Although, I could commit my change locally, I can not push to origin master

I run

$ git remote add origin [email protected]:username/test.git

I get

fatal: remote origin already exists.

I run

$ git push -u origin master

I get

ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

What's wrong with this?

like image 299
Koh Takahashi Avatar asked Apr 09 '12 02:04

Koh Takahashi


People also ask

How do I push origin to master?

git push origin master will push your changes to the remote server. "master" refers to master branch in your repository. If you want to push your changes to any other branch (say test-branch), you can do it by: git push origin test-branch. This will push your code to origin of test-branch in your repository.

Why isn't my git push is not working?

It may be possible that push permission is not provided to the user pushing the code changes. I suggest checking the user permissions. If the push permission is present, then it may be possible that there is a pre-push git hook in the repo and your push isn't in accordance with it.

How do I push master branch to origin remote?

Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch. Simply use a git push origin command on subsequent pushes of the new branch to the remote repo.

How do I force a master push on GitHub?

To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).


3 Answers

2-way to do this
1st:-

 git remote set-url <name> <newurl>

example:-

git remote set-url origin [email protected]:username/test.git

2nd:-

What you need to do is change your 'origin' setting.you edit .git/config in your project root, which may look something like this:

...
[remote "origin"]
url = git://[email protected]/git/repos/path
fetch = +refs/heads/*:refs/remotes/origin/*
...

or if your 'remote' is actually local:

...
[remote "origin"]
url = /path/to/repos/on/this/machine
fetch = +refs/heads/*:refs/remotes/origin/*
...

All you need to do is edit that file with your favorite editor and change the url = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll be happily pushing and pulling to and from your new remote location.

like image 175
Sumit Singh Avatar answered Nov 01 '22 14:11

Sumit Singh


I know this question is older but I came across it while trying to find the answer for an error I was having and I found the answer. As of Oct 2020 any new repository created the branch will be called main and not master. GitHub is renaming the primary branch due to racism with master/slave properties. You will want to type git push orgin main.

like image 33
innocentrage Avatar answered Nov 01 '22 13:11

innocentrage


It looks like there's a bad entry for origin in your config file.

Edit your repository's .git/config file to change it; the format is fairly self-explanatory, but post its contents if you have trouble.

like image 1
Danica Avatar answered Nov 01 '22 12:11

Danica