fts_acer fts_acer - 1 year ago 41
Git Question

Why does my Git remote URL need to include my username only on some systems?

The Cliff's Notes of my original issue is that I have a thesis project repo hosted on GitHub that I'm using multiple machines to access for both reading and writing to the repo. I have my home desktop, my laptop, my professor is using the repo on his machine, and we have our "production" server. We've been using this repo with no issues on our personal machines, via Win7, Win8.1, and Ubuntu 14.04. On all of these systems we're using the following remote URL:


...and it works perfectly for pulling and pushing against our repo. However, on the production server, using CentOS 6.x (not sure if that matters) we were getting an error 403 Forbidden, with no opportunity to even try providing a username or password. After troubleshooting this for some time (as a total n00b) I finally discovered that on the CentOS machine only I have to use the remote URL:


Why would this be the case on only one of our machines?


VonC's answer below was helpful in getting an understanding of the root of the problem. My Git version on CentOS 6.x is way behind the current version, despite the fact
yum update
reports it being up-to-date.

The CentOS repos are known to lag behind the most up-to-date packages. Using Git as my example, the most up-to-date version of Git I can get with the CentOS 6 base repository is 1.7.1 which is way, way behind the real current version of Git. I have tried a plethora of solutions including those listed in VonC's helpful answer below such as using the
repositories to override base and install newer versions of Git, as well as others not listed here, all to no avail. My next step is to try building Git from source, and I will report the results if anything comes of it.

Answer Source

As mentioned in GitHub help page "HTTPS cloning errors", this is because your CentOS 6.x has an old git version. (type git --version to confirm)

If you can upgrade git there, you won't need to attach your username to the url.
If you cannot upgrade, change the remote url to add your username is indeed a workaround.

git remote set-url origin https://yourusername@github.com/user/repo.git

You can also try to add your username for any github url:

git config --global credential.https://github.com.username YOUR_USERNAME

But if git is too old, that last command might not even be supported.