SOLFIND
Web Lens
Portal home

Finding and understanding example code - GitHub Docs

https://docs.github.com/en/get-started/learning-to-code/finding-and-understanding-example-code • 252 KB fetched
Open original page


Finding and understanding example code - GitHub Docs Skip to main content GitHub Docs Version: Free, Pro, & Team Search or ask Copilot Search or ask Copilot Select language: current language is English Search or ask Copilot Search or ask Copilot Open menu Collapse sidebar Expand sidebar Scroll breadcrumbs left * Home * Get started * Learn to code * Finding example code Scroll breadcrumbs right Get started * * * Start your journey * What is GitHub? * Learning resources * Create your repository * Plan your work * Connect locally * Write and store code * Review changes * Deploy automatically * Onboarding * Getting started with your GitHub account * Getting started with GitHub Team * Getting started with the GitHub Enterprise Cloud trial * Getting started with GitHub Enterprise Cloud * Using GitHub * Hello World * GitHub flow * Connecting to GitHub * Communicating on GitHub * Feature preview * Supported browsers * GitHub Mobile * Allow network access * Connectivity problems * Learning about GitHub * GitHub's plans * GitHub language support * Types of GitHub accounts * Access permissions * GitHub Advanced Security * Changes to GitHub plans * GitHub glossary * Learn to code * Set up Copilot for learning * Get started with Git * Finding example code * Reuse people's code * Local development * Debug with Copilot * Getting feedback on your code * Storing secrets safely * Secure your code * Secure your dependencies * Accessibility * Manage theme settings * Keyboard shortcuts * GitHub Command Palette * Writing on GitHub * Start writing on GitHub * Quickstart * About writing & formatting * Basic formatting syntax * Work with advanced formatting * Organized data with tables * Collapsed sections * Create code blocks * Create diagrams * Mathematical expressions * Auto linked references * Attaching files * About tasklists * Permanent links to code * Using keywords in issues and pull requests * Work with saved replies * About saved replies * Creating a saved reply * Editing a saved reply * Deleting a saved reply * Using saved replies * Share content with gists * Creating gists * Forking and cloning gists * Saving gists with stars * Moderating gist comments * Explore projects * Discover projects * Contribute to a project * Finding open source projects * Contribute to open source * Use Copilot to explore projects * Save repositories with stars * Following people * Following organizations * Git basics * Set up Git * Set your username * Caching credentials * Repeated credential prompts * macOS Keychain credentials * Git workflows * About remote repositories * Manage remote repositories * Associate text editors * Handle line endings * Ignoring files * Git cheatsheet * Using Git * About Git * Push commits to a remote * Get changes from a remote * Non-fast-forward error * Splitting a subfolder * About Git subtree merges * About Git rebase * Git rebase * Resolve conflicts after rebase * Special characters in names * Maximum push limit * Archive account and public repos * Request account archive * GitHub Archive program * Using GitHub Docs * Docs versions * Hover cards * GitHub Docs API * GitHub Certifications * About GitHub Certifications * Registering for an exam Finding and understanding example code Improve your coding skills by learning from example code on GitHub. Copy as Markdown Learn to code with GitHub Copilot Article 3 of 10 Next : Reusing other people's code in your projects In this article * How can I learn from code on GitHub? * Finding an example project * Orienting yourself within the project * Navigating the source code * Understanding the source code * Next steps How can I learn from code on GitHub? Learning from projects on GitHub is a great way of learning new techniques and finding inspiration for your own projects. However, with millions of publicly available repositories on GitHub, finding code that applies to your project can be overwhelming. Even after you find the perfect repository, it can be difficult to navigate the codebase to find useful examples. Instead of trying to understand an entire project, a better approach is to pick a single feature or function and see how it works. We can use Copilot Chat and GitHub's search functionality to locate a feature and follow it through the codebase. This is a great way to learn as we can see how the feature works all the way from the backend to the frontend. In this guide, you'll learn how to do both by following an example scenario : learning how to load and display data from files on a Jekyll website. Then, you can apply the tips and techniques to other projects and programming languages. Finding an example project The first step is to find the right project to learn from. Use Copilot Chat to identify a repository The fastest way to find a project with code that you can learn from is to ask Copilot Chat to find repositories that match your criteria. Open Copilot Chat and start a general purpose chat. Then ask: Can you find some popular repositories that use Jekyll to display data from files in the repository? Copilot will return links to relevant repositories, and you can ask follow-up questions about the repositories. Often, Copilot will end its response with a link to GitHub search with more results. Next, we'll review these results. Using search to identify more options If Copilot included a link to search results, follow the link. If not, form your own search query by following the steps below. * Navigate to Advanced search . * In the "Advanced options" section, use the "Written in this language" dropdown to select a programming language. For our Jekyll site, we'll select "HTML". * Optionally, under "Repositories options", next to "With this many stars", type >150 . This will help you find popular repositories that are likely well maintained. * Back at the top of the page, click Search . Tip We can further narrow down your search results by adding topics and text to the search query. For example, topic:jekyll "blog" would return repositories the owner has classified as related to Jekyll and with the word "blog" in the repository name or description. For a list of popular topics, see Topics on GitHub . Choosing a project After reviewing the results from Copilot and search, we decide to use the github/choosealicense.com repository. This repository contains the source code for Choose a License , a Jekyll website that shares information about open source licenses. We're particularly interested in the Licenses page, which displays popular open source licenses from data files. Orienting yourself within the project Before we dig into the code for displaying data files, let's orient ourselves in the repository in general. It can be difficult to know where to start when you first visit a repository. While each project will organize itself in its own individual way, there are common documentation methods that we can usually rely upon to get our bearings. The README.md file It's always a good idea to read the README.md file, which is the front page of a repository and is automatically rendered beneath the list of files. Different maintainers will include different information, but you can often find information about the project, how to build it on your local machine, and links to documentation. In the github/choosealicense.com repository, the README.md file explains where the license files live ( /_licenses ), the attributes each license can have, and how to get the website running on your computer. Using Copilot Chat If the README.md file doesn't give you all the answers, you can ask Copilot to help you navigate the repository and locate functionality. To open Copilot Chat, click the icon next to the search bar and ask your question. For example: What is the main landing page for this Jekyll website? When you ask Copilot questions about a repository, it can return the relevant files, explain the part they play in the functionality, and include links. The repository's wiki Another possible source of information is the repository's wiki , a section of the repository specifically for hosting documentation. Every repository on GitHub comes equipped with the ability to use a wiki, but not every repository uses it. To access the wiki, click the Wiki tab in the repository. Releases If the repository's source code builds into an executable file, some repository maintainers will use the repository's releases to publish binary files. You can download and run these binary files to examine how the application works while exploring the codebase, without needing to build the project yourself. You can find a repository's releases in the sidebar, to the right of the list of files and README.md. Internal documentation You can also look for internal documentation in the repository's contents. This could be a single Markdown file or a directory full of Markdown files. Common names to look for include "docs", "documentation", "wiki", "resources", "help", and "manual". Navigating the source code Now that we understand the overall structure of the repository, it's time to use GitHub search to find to the specific functionality we're looking for. When you're in a repository and click into the search field at the top of the page, GitHub will automatically add the repo search qualifier so your search results are constrained to the repository you're viewing. To get started, we need something to search for. This could be a string of text unique to the feature we're examining, or we could look at the HTML source of the page and find a particular class or id attribute. In our example, we'll search for the text at the top of the licenses page , using this query: repo:github/choosealicense "If you’re looking for a reference table?" . This returns one result, a file named licenses.html . Now we can click on the result and dig deeper! licenses.html is the source of the "Licenses" page we were looking for. We can see the string that we searched for and that each of the licenses is included with the code below: {% include license-overview.html license-id="agpl-3.0" %} Understanding the source code Now that we've found the specific code we're interested in, we can move on to understanding it. Asking Copilot Chat about the code You can use Copilot to learn more about a file or even specific lines of code. Copilot will combine information about the programming language with the context from the repository to answer your questions in great detail. Let's ask Copilot to explain what's happening on line 11, with the {% include %} tag. Click the line number. Then, to the right of the line, click . In the chat window, ask: What's happening in this line? Copilot will explain that the line is including the license-overview.html file and passing along "agpl-3.0" as the license-id to display. Tip If you don't understand a response from Copilot Chat, you can always ask it to simplify the answer or expand on a particular part of it. Reading comments Comments are human readable annotations that you can use to understand the code and are not executed. They are usually delimited with characters such as // or /* . There are a few types of comments to look for: * Line : Single-line comments that describe what a particular line is doing * Block : Multi-line comments that might describe what an entire function or file is doing * File : A block comment at the very beginning of a file, providing an overview of that particular part of the codebase Looking up functions in programming language references Every programming language will have a reference online, explaining every aspect of the language. If you use a search engine to search for the programming language and the function, you should find a link to that function's reference page. For our example, searching for jekyll include in a search engine should return the "Includes" documentation in the Jekyll documentation. If we read further into Jekyll's documentation, we can see that the licenses themselves are a collection in the _licenses directory. Tip If you can't find a function in a programming language reference, it's likely that the function is defined in the codebase itself. Ask GitHub Copilot to locate it. To summarize what we've learned: the licenses.html file includes /_includes/license-overview.html for each license shown. The /_includes/license-overview.html file matches the license-id provided to a license in the /_licenses collection and renders the details. Experimenting with small changes If you're able to run the project locally on your computer, a great way to learn is to make little changes to see what happens. You can start by changing text, then move on to making bigger changes, such as experimenting with how functions and files interact with each other. Try finding the license-overview.html file in the _includes directory, then making changes to how the license is displayed or experimenting with how the license is loaded from the collection. You could change the metadata at the beginning of one of the license files, change which attributes are displayed in license-overview.html , or even try adding your own attribute. When you've made your change, you can test it by following the README.md instructions to view it in your browser. Applying what we've learnt The github/choosealicense.com repository is a great example of a large Jekyll project and demonstrates just how much is possible with Jekyll and GitHub Pages. Can you apply what you've learnt from the structure of the repository, how it uses collections, and the way it includes the license data to build your own project? Next steps Now that you understand how the example code works, you may want to reuse it in your own project. Code reuse is a powerful part of software development, but there are important steps to follow to do it correctly and legally. For a full tutorial, see Reusing other people's code in your projects . Up next Reusing other people's code in your projects Step 3 of 10 in Learn to code with GitHub Copilot Help and support Did you find what you needed? Yes No Privacy policy Help us make these docs great! All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request. Make a contribution Learn how to contribute Still need help? Ask the GitHub community Contact support Legal * © 2026 GitHub, Inc. * Terms * Privacy * Status * Pricing * Expert services * Blog

Links found on this page

  1. Skip to main content [direct]
  2. GitHub Docs [direct]
  3. Get started [direct]
  4. Learn to code [direct]
  5. What is GitHub? [direct]
  6. Learning resources [direct]
  7. Create your repository [direct]
  8. Plan your work [direct]
  9. Connect locally [direct]
  10. Write and store code [direct]
  11. Review changes [direct]
  12. Deploy automatically [direct]
  13. Getting started with your GitHub account [direct]
  14. Getting started with GitHub Team [direct]
  15. Getting started with the GitHub Enterprise Cloud trial [direct]
  16. Getting started with GitHub Enterprise Cloud [direct]
  17. Hello World [direct]
  18. GitHub flow [direct]
  19. Connecting to GitHub [direct]
  20. Communicating on GitHub [direct]
  21. Feature preview [direct]
  22. Supported browsers [direct]
  23. GitHub Mobile [direct]
  24. Allow network access [direct]
  25. Connectivity problems [direct]
  26. GitHub's plans [direct]
  27. GitHub language support [direct]
  28. Types of GitHub accounts [direct]
  29. Access permissions [direct]
  30. GitHub Advanced Security [direct]
  31. Changes to GitHub plans [direct]
  32. GitHub glossary [direct]
  33. Set up Copilot for learning [direct]
  34. Get started with Git [direct]
  35. Reuse people's code [direct]
  36. Local development [direct]
  37. Debug with Copilot [direct]
  38. Getting feedback on your code [direct]
  39. Storing secrets safely [direct]
  40. Secure your code [direct]
  41. Secure your dependencies [direct]
  42. Manage theme settings [direct]
  43. Keyboard shortcuts [direct]
  44. GitHub Command Palette [direct]
  45. Quickstart [direct]
  46. About writing & formatting [direct]
  47. Basic formatting syntax [direct]
  48. Organized data with tables [direct]
  49. Collapsed sections [direct]
  50. Create code blocks [direct]
  51. Create diagrams [direct]
  52. Mathematical expressions [direct]
  53. Auto linked references [direct]
  54. Attaching files [direct]
  55. About tasklists [direct]
  56. Permanent links to code [direct]
  57. Using keywords in issues and pull requests [direct]
  58. About saved replies [direct]
  59. Creating a saved reply [direct]
  60. Editing a saved reply [direct]
  61. Deleting a saved reply [direct]
  62. Using saved replies [direct]
  63. Creating gists [direct]
  64. Forking and cloning gists [direct]
  65. Saving gists with stars [direct]
  66. Moderating gist comments [direct]
  67. Discover projects [direct]
  68. Contribute to a project [direct]
  69. Finding open source projects [direct]
  70. Contribute to open source [direct]
  71. Use Copilot to explore projects [direct]
  72. Save repositories with stars [direct]
  73. Following people [direct]
  74. Following organizations [direct]
  75. Set up Git [direct]
  76. Set your username [direct]
  77. Caching credentials [direct]
  78. Repeated credential prompts [direct]
  79. macOS Keychain credentials [direct]
  80. Git workflows [direct]