I created a fork
of another repository namely javacode (https://github.com/Originalusername/javacode
) on GitHub
and the forked repo is created under my user name(https://github.com/Myusername/javacode
).
After that, I decided to clone
the forked repo under my user name so that I could make changes to it and commit
and push
in my forked repository instead of the original repository since GitHub
is an open source but I don’t have access to make changes to the original repo as it is owned by someone else. I can later request for PULL
to pull my changes to the original owner/author of the repo.
Therefore, to clone
my forked repo to my local machine for making changes, I opened git bash
on the Windows machine
as git
is installed on my machine and runs the command git clone https://github.com/Myusername/javacode.git
.
I got this forked repo URL from Github -> Under my forked repo -> click on <> Code -> Under HTTPS –> Copy the URL to clipboard
and run the above command git clone forkedrepoUrl
.
After the repo was cloned, I opened it using Intellij from the path of the cloned repo on my Windows PC. Make some changes to one of the files and on that changed file perform a right-click, select the option Git
from the menu, and then select the Commit
option to commit my changes first to the local cloned repo.
Alternatively, you can commit by running commands git add
and git commit
respectively on git bash
also.
However, when I tried to push
the changes to my forked repo on GitHub
by performing a right-click on the changed file and selecting the option Git
from the menu and from there selected Push
option this time to push my changes to the forked repository.
Alternatively, you can push by running the command git push
on the git bash
.
I got this error,
remote: Permission to originalusername/javacode.git denied.
fatal: unable to access 'https://github.com/originalusername/javacode.git/': The requested URL returned error: 403
I tried several times but got this error again and again. How could I push my changes to the fork repo rather than to the original repo, where I don’t have access to write anything? I can only raise a pull request to the original author later to merge my changes to their original repo after reviewing my changes.
First, open the
command prompt
on yourWindows machine
. Navigate to your folder where you want to clone the forked repo assuming you have forked the original repo under your username. Suppose, you want to clone the fork repo to the desktop of your Windows PC then you executecd desktop
to navigate to the desktop.After that run the
git clone fork-repo-url
to clone the fork repo to the local Windows machine.git clone https://github.com/myusername/javacode.git
this command will start cloning your fork repo on your desktop and will show the output like this on the command prompt.
Once cloning is done, you can then run
dir
to see if the clone directory is created on the desktop. If created then runcd javacode
to navigate to your cloned folder. Once you are in your cloned folder run the commanddir
again to see files cloned from the Github fork repo inside your desktop clone folder.After cloning, we need to set up a remote by running the following command on cmd.
git remote -v
This will list out the origin of the remote for this project which is from the fork.
origin https://github.com/myusername/javacode.git (fetch)
origin https://github.com/myusername/javacode.git (push)
Now, set up a remote to the main remote repo which allows syncing of the fork repo with the main repo. for this, we need the URL of the original repo.
You can get this main original repo URL by clicking on the link after your “repo forked from the link” and there under Code –> under HTTPS -> copy the original repo URL to the clipboard.
Now under the command prompt window type the command to add remote to the main original repo.
git remote add upstream https://github.com/Originalusername/javacode.git
after this run this command again on the command prompt,
git remote -v
This will now list the fork repo as the origin and the original repo as upstream.
Now try to open this cloned project on IntelliJ make changes commit and push to your fork repo it will be successful and you will be able to see your changes inside the GitHub forked repo. Now, if you want, you can request the original author to pull your changes using a pull request on GitHub.