error: The requested URL returned error: 403 Forbidden while accessing Github repo

After a long time I created a repo on my Github account.Creating a repo is quite easy on Github, simply login to your account and click on ‘create repo’ button. After creating git repo, now it was time to push all my codes from my desktop to github repo.

After cloning the repo into my system, I copied all my coded into git cloned directory. And tried to push my code into gtihub repo. But got the error message “error: The requested URL returned error: 403 Forbidden while accessing https://github.com/sharadchhetri/skctheme.git/info/refs

The error was quite clear that the problem was with URL. I again used my old generic steps for git. Finally it is solved and all codes are successfully pushed into github repo.

In below section, I am writing step by step how I pushed the code in Github repo successfully
Follow the given below steps from where(Desktop/Server) you want to push the code into Github repo :

Step 1: Clone the github repo into your system. (You should first create a repo in Github)

Get repo url at right hand sidebar of your repo page. Replace your github repo’s HTTPS url with https://github.com/USER-NAME/REPO-NAME.git

git clone https://github.com/USER-NAME/REPO-NAME.git

For EXAMPLE:

git clone https://github.com/sharadchhetri/testrepo.git

After cloning will be finished, you will find the directory name matching with the name of Github repo name you just cloned.

Step 2 : Copy your code or files to REPO-NAME directory

For example, I have saved my codes in my desktop at /home/sharad/MyCode directory. Here, I am copying all codes and child directories into REPO-NAME directory .

cp -rvf /home/sharad/MyCode/* /home/sharad/testrepo

Step 3 : Change to git cloned directory i.e REPO-NAME.

cd REPO-NAME

Step 4 : Set Github account username and email id for authentication

git config --global user.email "your-email-id@example.com"
git config --global user.name "Your-Github-UserName"

Step 5: Set Github URL. (This section is actually solution of this problem)

git remote set-url origin https://Your-Github-UserNAme@github.com/Your-Github-UserNAme/REPO-NAME

For EXAMPLE.

git remote set-url origin https://sharadchhetri@github.com/sharadchhetri/testrepo.git

Step 6: Now add all files and directory by using below given command inside REPO-NAME directory
(There is a dot in command, can you see that!)

git add .

Step 7: Now write comment on commit

git commit -m 'my first commit'

Step 8: Now push the code in Github repo.
Be ready with your github account password because it will ask.

git push -u origin master

I hope the solution also work for you.

9 thoughts on “error: The requested URL returned error: 403 Forbidden while accessing Github repo”

  1. I tried hours to solve this issues, searched for various solutions on stackoverflow. Finally, this method worked for me. Thank You.

    Reply
  2. I didnt understand why i got the error, but upon reading your post solved the issue of error 403. I’m using Aptana studio 3 with git to push the code. Thanks for your post.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.