Git: Can't Push (Strange Config Issue)

GIT: Can't Push (Strange Config Issue)

Okay, so I fixed it, but the method is absolute witchcraft.

I tried to isolate the problem by purging GIT, deleting the config file, reinstalling GIT, then creating a local bare repository, then cloning it, then attempting to push from there. Pretty much like this:

sudo apt-get purge git-core
rm -f ~/.gitconfig
sudo apt-get install git-core
cd /git
mkdir foo
cd foo
git init --bare
cd /var/www
git clone /git/foo
cd foo
touch blah.txt
git add -A
git config --global user.name "Name"
git config --global user.email "user@email.com"
git commit -m "Blah"
git push

...same exact error message, no change there. (Still some serious witchcraft.)

Then, I deleted one of my repositories that doesn't have a local origin (it connects to its origin via SSH) and cloned the repository anew after deleting it (with a fresh git clone ssh://... command).

I got an error from the clone command:

remote: Malformed value for push.default: simple
remote: Must be one of nothing, matching, tracking or current.

Ah ha! Now it says remote instead of error. So the remote doesn't support this behavior. (That doesn't explain why the error persists on local-only repositories with local origins, then, though.)

So I then SSH'ed into the remote server and updated the git-core there to the latest version, re-attempted to clone the repository from my local machine, and it worked.

Now, I can finally git push. Insanely, this also fixed it so I can git push from the entirely local /var/www/foo to the also entirely local /git/foo (the local origin bare repository). SSH'ing into this remote server and updating it somehow - WITCHCRAFT - fixed my local machine's error.

Why on earth the entirely local repos care about an entirely different machine's GIT version is... beyond me. How utterly, utterly insane.

Git push results in Authentication Failed

If you enabled two-factor authentication in your GitHub account you
won't be able to push via HTTPS using your accounts password. Instead
you need to generate a personal access token. This can be done in the
application settings of your GitHub account. Using this token as your
password should allow you to push to your remote repository via HTTPS.
Use your username as usual.

Creating a personal access token

You may also need to update the origin for your repository if it is set to HTTPS. Do this to switch to SSH:

git remote -v
git remote set-url origin git@github.com:USERNAME/REPONAME.git

Git error when trying to push -- pre-receive hook declined

You should ask whoever maintains the repo at git@mycogit/cit_pplus.git.

Your commits were rejected by the pre-receive hook of that repo (that's a user-configurable script that is intended to analyze incoming commits and decide if they are good enough to be accepted into the repo).

It is also a good idea to ask that person to update the hook, so it would print the reasons for the rejection.

If the maintainer is you yourself, then it looks like you've got a problem with your setup on the server-side. Please share more information then.

git pushes with wrong user from terminal

Despite all the great options given by other users, the only way to fix this was to reinstall git completely and type git config --global push.default simple to rewrite good credentials.

Git using the wrong email for push

TL;DR

You need to switch your credentials. Start with VonC's answer here.

What's going on

Note specifically the URL here:

... unable to access 'https://github.com/...'

Start with this: git push does not use your configured user.email! It uses the URL you provide, usually via a remote name like origin: there's a setting, remote.origin.url, that holds the URL.

The URL itself begins with one of the various "scheme" names, like ssh:// or https://. After the double slash is a host name—technically, this can include user:password@host.dom.ain but don't do that; at most put in user@host.dom.ain—and then the rest of the string is provided to that host. Or, you can use git@github.com:path/to/repo, which is short for ssh://git@github.com/path/to/repo.

Since you specifically asked for https, Git will get the user name and password from a credential helper. The specific credential helper that Git uses depend on a lot of things. The most important, in order, are these two:

  • What is your host OS? Windows has Windows-specific credential helpers, OS X has osx-keychain based helpers, and others have the store and cache helpers.

  • What version of Git are you using? Almost all modern versions are much better than the ancient ones, but there are still some ancient (1.7 and early 1.8) Git versions still in use.

For (much) more about credential helpers when using HTTPS, see Is there a way to skip password typing when using https:// on GitHub? I note that you added:

here's an additional weird thing: I can push using the Github Windows client but I can't push using the Git GUI.

This implies that you're using Windows (which I avoid...). Obviously their Github Windows Client is using a different credential helper than the Git GUI.

I prefer to use SSH, which means I set up my ssh keys and set my URL to use ssh://git@github.com/.... When using SSH, GitHub ends up looking up the public key that your SSH client—your Git, in other words—sends to find who is connecting, and then uses that to decide who you are and whether you can access that repository.

So where does your user.email get used?

Once your Git gets authorized and is successfully talking to another Git on GitHub, your Git then pushes commits. The commits themselves—which you've already made, at some point well before you ran git push—contain strings derived from your user.name and user.email settings.

It's git commit, not git push, that uses the user.name and user.email settings. These are just configuration settings, not credentials.

In other words, by the time you run git push, it's way past the time Git was looking at your user.email setting. What you have set now no longer matters at all. What you had set in the past matters if and only if you push some commits that used its setting.



Related Topics



Leave a reply



Submit