Sunday, September 12, 2021

 GitHub - Forking - time now 

In simple languate, forking is creating a copy of an existing repository under your own account. Forking a repository allows you to freely experiment with a copy of the existing code base (if public), without the fear of breaking the original code base, and all this happens in your account. Forking also gives you the ability to contribute to a project, by adding additional functionality.

The steps would be:

  1. Fork the repository - In the origin repository you get this option (right corner of the page)
  2. Create a new branch - Command 
  3. Submit a pull request to the owner of the original project - If the owner approves your fix, your work should then be merged into the original repository.

Forking Steps

Fork a remote repository, configure upstream, (to get updates from the original repository) and propose a change to the owner

  1. While you are logged into your account, go to a public repository available.
  2. Click on "Fork", in the top right of this page. This will create a copy of the repository under your account. This will copy files in your account. 
  3. Now we will clone in "local". Copy the url and  will be redirected to your account's version of the repository, run command git clone [URL]
  4. CD to your folder. Run command git remote -v to confirm that you have cloned the correct repository. The output should show fetch and push, but the URL will be pointing to your repository.

Updating forked repository from original

Now that we have the local copy of the code, we will link to the source to keep getting updates when files chanages in source.  

  1. Run command git remote -v to make sure that the upstream to the original repository is not set up yet.
  2. In your browser, go to the original git repository and copy the repository URL (the one used for cloning).
  3. Execute the following comma git remote add upstream [URL] . Next check that this has worked, execute command git remote -v and check the fetch and push
  4. Now you will pull the changes from the original repository into yours, which you can do by executing the git fetch upstream command 
  5. You will want to update the main branch, so will merge the upstream/main into the local origin/main by executing the git merge upstream/main command and then git push
    origin/main branch.
The key commands are summarised below:
git clone [url] (after you have forked on the browser - url of from your account)
git status (keep checking the status)
git remote - v (check the which remote and source fork is being referred)
git remote add upstream [url] (url of the source - this will ensure updates are received)
git fetch upstream (get updated files from upstream)
git merge upstream/mail (merg local files from upstream main branch)
git push (update the local with your remote)

If you have queries, do drop in your queries below.

...HaPpY CoDiNg
Partha 

No comments:

Post a Comment