At the heart of GitHub is to make team collaboration seamlessly. You can only contribute to a public repository or a private repository where you have been added as a collaborator.
Cloning a git repository copies the content of the remote repository to your local device. While on the repository you have forked, click the green clone or download button and copy the displayed URL.
On your device terminal, run the below command to clone the repository.
git clone URL_OF_Forked_Repository
To start working on the codebase, you must first navigate to the project folder and create a branch.
git checkout –b branchname
After making the changes on your local repository, you need to make them available in the remote repository. Run the below commands
git status to check uncommitted changes
git add * to add all the changes to the staging area
git commit –m ‘the commit message’ command to commit the changes
git push origin branchName to push the changes to GitHub
on your GitHub account move to the repository that you have just committed the changes and refresh the page. You will see a green Compare and Pull request button. Click on it and the maintainer will merge the commits.
While pulling the request you may run to some troubles such as having your repository several commits behind the main repository. That happens when a team member pull request gets merged after you had forked the repository.
Consequently, you need to upstream the changes to sync it with your repo.
you should add a remote upstream repository as the parent of your local repo. That will give it a reference project where it will inherit any changes made.
git remote -v to check if your repo has a parent
If no parent is listed, run the below command to add one.
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
To sync the repo, first, move to the main branch.
git checkout main
Now, fetch the changes from the original repository to your repo, by running the below command;
git fetch upstream
Lastly, merge the changes with the main branch.
git merge upstream/main
That’s it, your forked repo is up to date, you can go on push the changes and pull the request.