Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git/GitHub can't push to master

Tags:

git

github

People also ask

Why is git push origin master not working?

If git push origin master not working , all you need to do is edit that file with your favourite 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 easily be able to push and pull to and from your new remote location.

Why can't I push code to GitHub?

To push a branch on remote, your branch needs to have the latest changes present in remote repository. If you get the failed to push error, first do git pull the branch to get the latest commits and then push it.

Can't push to master GitLab?

It appears that GitLab does not allow you to push directly to master . This is a common practice. Instead, you should create a merge request from your feature branch to master. When you accept the merge request in the GitLab UI, it will automatically create a merge commit and move the master branch.


GitHub doesn't support pushing over the Git protocol, which is indicated by your use of the URL beginning git://. As the error message says, if you want to push, you should use either the SSH URL [email protected]:my_user_name/my_repo.git or the "smart HTTP" protocol by using the https:// URL that GitHub shows you for your repository.

(Update: to my surprise, some people apparently thought that by this I was suggesting that "https" means "smart HTTP", which I wasn't. Git used to have a "dumb HTTP" protocol which didn't allow pushing before the "smart HTTP" that GitHub uses was introduced - either could be used over either http or https. The differences between the transfer protocols used by Git are explained in the link below.)

If you want to change the URL of origin, you can just do:

git remote set-url origin [email protected]:my_user_name/my_repo.git

or

git remote set-url origin https://github.com/my_user_name/my_repo.git

More information is available in 10.6 Git Internals - Transfer Protocols.


Use Mark Longair's answer, but make sure to use the HTTPS link to the repository:

git remote set-url origin https://github.com/my_user_name/my_repo.git

You can use then git push origin master.


Mark Longair's solution using git remote set-url... is quite clear. You can also get the same behavior by directly editing this section of the .git/config file:

before:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git://github.com/my_user_name/my_repo.git

after:

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

(And conversely, the git remote set-url... invocation produces the above change.)


There is a simple solution to this for someone new to this:

Edit the configuration file in your local .git directory (config). Change git: to https: below.

[remote "origin"]
    url = https://github.com/your_username/your_repo

I had this issue after upgrading the Git client, and suddenly my repository could not push.

I found that some old remote had the wrong value of url, even through my currently active remote had the same value for url and was working fine.

But there was also the pushurl param, so adding it for the old remote worked for me:

Before:

[remote "origin"]
    url = git://github.com/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    pushurl = [email protected]:user/repo.git

NOTE: This part of file "config" was unused for ages, but the new client complained about the wrong URL:

[remote "composer"]
    url = git://github.com/user/repo.git
    fetch = +refs/heads/*:refs/remotes/composer/*

So I added the pushurl param to the old remote:

[remote "composer"]
    url = git://github.com/user/repo.git
    fetch = +refs/heads/*:refs/remotes/composer/*
    pushurl = [email protected]:user/repo.git