modules

Git: Forking

Key Terms

A Typical Setup for Forked Code

Branching vs Forking

Here is a good example repository that makes use of issues and pull requests: https://github.com/openelections/

❇️ Example (shorter - no local repository)

  1. Step 1: Fork my repository dmil/simple-website.

  2. Go to Settings > GitHub Pages and select the “master” branch as the source. Wait a few seconds and then go to http://your-username.github.io/simple-website to make sure github pages is set up correctly.

  3. Normally I’d clone the forked repository locally onto my computer, push changes to the fork, then issue a pull request. For the sake of time lets cut that step out. Make one small edit in your fork of this code directly in GitHub.

  4. Create a pull request. Note that this time we are creating pull request across repositories instead of just across branches within the same repository. The base will be dmil/simple-website/master while the compare will be your-username/simple-website/master.

  5. Compare your website http://your-username.github.io/simple-website to mine: http://dhrumilmehta.com/simple-website/

  6. I will now merge your pull requests and we can see what changes you all make to the website over time. There’s a good chance we may run into some merge conflicts as well.

❇️ Example (Longer)

  1. Step 1: Fork my repository dmil/simple-website.

  2. Go to Settings > GitHub Pages and select the “master” branch as the source. Wait a few seconds and then go to http://your-username.github.io/simple-website to make sure github pages is set up correctly.

  3. Clone the forked repository to your Development folder.

     git clone git@github.com:XXXX/XXXX.git
    
  4. Create a feature branch with your name.

     git checkout -b <your name>
    
  5. Make a random change.

  6. Commit and push the change.

     git commit -m "describe your random change here"
     git push
    
  7. Create a pull request. Note that this time we are creating pull request across repositories instead of just across branches within the same repository. The base will be dmil/simple-website/master while the compare will be your-username/simple-website/feature-branch-name.

  8. Create another pull request within the fork itself where the base is your own master branch. More explicitly, the base is your-username/simple-website/master and the compare is your-username/simple-website/feature-branch-name. Merge this pull request.

    Note: Draw diagram on board

  9. Compare your website http://your-username.github.io/simple-website to mine: http://dhrumilmehta.com/simple-website/

  10. I will now merge your pull requests and we can see what changes you all make to the website over time. There’s a good chance we may run into some merge conflicts as well.

Woohoo! You just collaborated open-source.

Open source collaboration is great for:

More Links

➡️ Try It

  1. Find another partner, and fork their <username>-simple-website.
  2. Clone your fork onto your local computer and create a feature branch called endorsement.
  3. Put an endorsement on their webpage as the last item on the site.
     <h2> Endorsements </h2>
     <p> You are a really cool person. - Dhrumil</p>
    
  4. Commit this endorsement and push it to your fork..
  5. Issue a pull request back to that person’s github repo.

Pull Requests and Issues in the Wild

➡️ Try It

Make an issue on my simple-website repository: https://github.com/dmil/simple-website