Thursday, January 14, 2016

Dealing with github error: The requested URL returned error: 403 while accessing

Above error means -I have tried to access a git project and I am not authorized .
I will show you one case to get this error and what is fix.

1-Create a github repository


-I have logded in to https://github.com/ using my github using  github credential
-I have created  a repository nagios_plugins (with default options)



2-Create local repository


$ mkdir nagios_plugins
$ cd nagios_plugins
$ echo "# nagios_plugins" >> README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin https://github.com/nansari/nagios_plugins.git
$ git push -u origin master


--and I get following error !!

error: The requested URL returned error: 403 while accessing https://github.com/nansari/nagios_plugins.git/info/refs

fatal: HTTP request failed


3-How to fix

--Now, we know, a case where we see this error. Let us fix it. Since url is https - it need some kind of authentication - that we have not configured or provided so for.

--https access to github requires username and password. here is how we can configure git to use a username for each push and pull command. 

--First, I checked what is remote configuration.

$ git remote -v
origin  https://github.com/nansari/nagios_plugins.git (fetch)
origin  https://github.com/nansari/nagios_plugins.git (push)


--Okay, I will modify origin to use my github username.

$ git remote set-url origin https://nansari@github.com/nansari/nagios_plugins.git
$ git remote -v
origin  https://nansari@github.com/nansari/nagios_plugins.git (fetch)
origin  https://nansari@github.com/nansari/nagios_plugins.git (push)
$ cat .git/config


--And, all done ! I am successfully able to push my local branch to remote.

$ git push -u origin master
Password: xxxxxx
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 511 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://nansari@github.com/nansari/nagios_plugins.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin by rebasing.


3-A step ahead - pushing local branch to remote


--If you are working in local branch other than master branch, you need to commit change on your local branch and then push your local branch to remote master

$ git push origin local_branch:master
Password: xxxxxx
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 320 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To https://nansari@github.com/nansari/
nagios_plugins.git   12b060a..fc3936b  local_branch -> master
 











No comments:

Post a Comment