GitHub is an online platform for storing, managing, and collaborating on projects that use Git version control. It is especially useful when you work on the same project from more than one computer.
For example, you might use a portable laptop while working at a coffee shop and another computer as your primary workstation at home. GitHub can act as the central home for your project’s code. You can upload changes from one computer and later download those changes to the other.
A single GitHub account can contain many repositories. You do not need to create a new account for every project. Each project of yours will have its own repository. Each repository is managed separately and has its own files, history, branches, collaborators, and privacy settings. For example, one account could contain a private software project, a public sample project, and a repository for website files.
Git and GitHub Are Different
Git is version-control software that runs on your computer. It records changes to your files over time, allowing you to review earlier versions, compare changes, and recover work if something goes wrong.
GitHub is an online service that stores Git repositories. It adds tools for sharing, collaboration, issue tracking, documentation, code review, and project management.
You can use Git without GitHub. You can also connect a local Git repository to another hosting service. However, GitHub is one of the most widely used services for hosting Git projects.
Public and Private Repositories
A GitHub repository can be public or private.
- A public repository can normally be viewed by anyone.
- A private repository can be viewed only by you and the people you authorize.
A private repository is usually the better choice for a personal project that is still under development or contains material that is not ready to be published.
What Is a Repository?
A repository is the main container for a project. It can include source code, templates, documentation, images, configuration files, and other files needed by the project.
A repository commonly includes a README file. The README introduces the project and may explain what the project does, how it is organized, how to install it, and how to use it.
GitHub can also add other useful files when a repository is created, including a licence file and a .gitignore file.
Working from More Than One Computer
GitHub can help you work on the same project from two or more computers.
A typical workflow looks like this:
- Clone the GitHub repository onto each computer.
- Pull the latest changes before beginning work.
- Edit and test the project locally.
- Commit the changes to Git.
- Push the commits to GitHub.
- On the other computer, pull the new commits before continuing.
This means that your project is not passed back and forth using USB drives, email attachments, or manually copied folders. Git keeps a structured history of the changes, while GitHub provides a central copy that both computers can reach.
It is important to avoid editing the same files independently on both computers without first synchronizing them. Otherwise, Git may need your help deciding how the competing changes should be combined.
Commits
A commit is a recorded checkpoint in the history of the project. It contains a group of changes and a short message explaining what was changed.
Useful commit messages might include:
- Add locations to initiative detail page
- Fix spacing before location commas
- Add Edit Note button to linked locations
Small, clearly described commits make it easier to understand the project’s history and reverse a particular change if necessary.
Branches
A repository normally begins with a primary branch called main. This branch usually represents the current working version of the project.
A branch allows you to work on a feature or experiment without immediately changing the main branch. For example, you could create a branch for a new search feature, work on it separately, and merge it into main after it has been tested.
A person working alone does not need to create a branch for every small change. For larger features or uncertain experiments, however, branches provide useful separation and protection.
Pull Requests
A pull request proposes that changes from one branch be reviewed and merged into another branch. Pull requests are commonly used by teams, but they can also help an individual developer document a major change before adding it to the main version of a project.
Files That Should Not Go on GitHub
Even a private GitHub repository should not contain passwords, access tokens, secret keys, or other sensitive credentials.
Projects often use a .gitignore file to prevent certain files from being included. Examples may include:
- Python virtual-environment folders
- Temporary files
- Editor configuration files
- Local environment files containing secrets
- Database files that should remain on one computer
For a project that uses SQLite, you may decide to keep the authoritative database on the home computer rather than routinely synchronizing the live database through GitHub. Database structure changes can instead be transferred using migration scripts, while selected content can be moved through controlled exports and backups.
GitHub Gists
A GitHub gist provides a convenient way to share a single file, a code sample, notes, or a small collection of files.
Gists can be public or secret. A secret gist does not normally appear in public searches, but it is not truly private. Anyone who obtains its URL may be able to view it.
Material that must remain restricted should be placed in a private repository or another properly secured system. Passwords and other credentials should not be placed in a gist.
GitHub as Part of a Practical Workflow
GitHub is useful not only for collaboration between people, but also for continuity between computers.
You can work on code using a portable laptop during the day, push the completed changes to a private GitHub repository, and then pull those changes onto your main home computer. Later, you can reverse the process and continue working from the portable computer.
GitHub does not replace your local files or your normal backup system. Instead, it adds version history, synchronization, and another protected copy of the project’s code.
For someone maintaining a long-term software project, those benefits can make GitHub an important part of a safe and organized development workflow.