Pages: Welcome | Projects

Git remotes push URL

2015/2/12
Tags: [ git ] [ Ideas ]

If you ever tried to inspect your remotes in git, you probably have notice that there are two distinct URLs for the push and the fetch operations. Today I realized why.

My repository is localized on a virtual machine other people (work colleagues) can reach. I clearly don't put my own SSH private key on the machine: in principle, anyone accessing the server could steal it and push stuff on my account. However, both me and the mentioned colleagues need to pull from a remote repository, so the following configuration was devised:

Git configures both the Push and the Fetch URLs to the same endpoint, and that's quite reasonable.

The use-case

What if we were in a rush, we decided to do some local hack and we want to push it? We stated that the fake user is not allowed to push.

The fix

Set-up the Push URL to the HTTPs endpoint!

git remote set-url --push <remote> https://github.com/...

Now your git push will ask you the authentication.

The caveat

Are you using a two-factor authentication in GitHub? Create an Access Token and use it as a password

Happy hacking