Random thoughts of a warped mind…

August 15, 2013

Github – swap origin urls

Filed under: All,Development,Git — Srinivas @ 16:07

Ever pull from a git repo that was open and you had pull access (ONLY) to and then wanted to push back to it later when you were granted that access? Chances are that you cloned from the git:// url (Git protocol) and trying to push back to it throws errors like this.

[[email protected] someproject]$ git remote -v
origin    git://github.com/username/someproject.git (fetch)
origin    git://github.com/username/someproject.git (push)

[[email protected] someproject]$ git push origin master
fatal: remote error:
  You can’t push to git://github.com/username/someproject.git
  Use https://github.com/username/someproject.git

This is because Github does not support push over Git protocol. You need to push via HTTPS/SSH instead. Do this:

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

Now you can push to the origin… (assuming you have been granted access to that project – check with git remote -v).

And if you’ve ever committed a confidential file (say access credentials) to Github – chances are that even in spite of a ‘git rm’ the file contents are still visible via the commit history… So a patient clicker may eventually get to it. Follow the instructions from here to safely purge that from git history. (Of course that wont help if some one cloned the repo before you got to this purge! And yeah, always makes sense to change the access keys/passwords/hostnames!).

Powered by WordPress