What is GitHub? Beginner Guide For GitHub
GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code. To understand exactly what GitHub is, you need to know two connected principles:
- Version control
- Git
What is Version Control?
Version control is a crucial tool for developers to effectively manage and track changes in a software project’s codebase. As the size and complexity of a project like WordPress increase, directly editing the official source code becomes risky and inefficient. Instead, version control enables developers to work safely through branching and merging.
Branching allows developers to create a duplicate, isolated copy of the source code repository. This will enable them to make changes to a specific part of the code without affecting the rest of the project. By working in this separate branch, developers can experiment, fix bugs, or add new features without directly modifying the main codebase.
Once the developer has successfully made the desired changes and verified their functionality, they can merge their branch back into the main source code. This integration process incorporates the developer’s modifications into the official codebase, making them part of the project as a whole.
Throughout this process, version control systems track every change made, creating a detailed history of modifications. This history provides transparency and allows developers to review, compare, and revert changes if necessary. It offers a safety net, ensuring that previous versions of the code can be restored if any issues arise.
What is Git?
Git is an open-source distributed version control system created by Linus Torvalds in 2005. Unlike centralized systems, Git allows each developer to have a complete copy of the entire codebase and its history on their local machine. This enables easy branching, where developers can work on different features independently, and merge, which combines changes from branches into the main codebase. With Git, developers can work offline, have full access to the codebase’s history, and efficiently manage code versions and collaboration.
What is GitHub?
GitHub is a for-profit company that provides a cloud-based Git repository hosting service. Its primary purpose is to simplify the use of Git, a popular version control system, for individuals and teams involved in software development, enabling them to effectively manage code versions and collaborate efficiently.
One of GitHub’s notable features is its user-friendly interface, which lowers the entry barrier for novice coders. Compared to using Git without GitHub, which typically involves more technical knowledge and command-line usage, GitHub simplifies the process and allows users to interact with Git repositories through a graphical interface.
Moreover, GitHub’s user-friendly nature extends beyond code repositories. Some individuals even utilize GitHub to manage projects of different types, such as writing books or other collaborative endeavours.
A key aspect of GitHub’s appeal is its free offering, allowing anyone to sign up and host public code repositories at no cost. This feature has contributed to GitHub’s popularity among open-source projects, as it provides an accessible platform for developers to collaborate, share code, and contribute to community-driven initiatives.
As a company, GitHub generates revenue through the sale of hosted private code repositories, as well as by offering business-focused plans that enhance team management and security features. These plans cater to organizations and provide additional functionalities for managing team members, ensuring code confidentiality, and maintaining robust security practices.
Why Use GitHub?
There are many reasons to use GitHub. Here are a few of the most important ones:
- Collaboration: GitHub makes it easy to collaborate with others on projects. You can create branches, make commits, and merge changes with ease.
- Version control: GitHub uses Git, which is a powerful version control system. This allows you to track changes to code over time and to revert to previous versions if necessary.
- Hosting: GitHub hosts your code in the cloud. This means that you can access your code from anywhere and that you don’t have to worry about storing it on your computer.
- Community: GitHub has a large and active community of developers. This means that you can get help and feedback from others when you need it.
Working with GitHub
Here are a few essentials on GitHub:
- Repositories
- Branches
- Commits
- Pull Requests
Repositories
A repository is a collection of code and other files related to a project. GitHub repositories are stored in the cloud and can be accessed from anywhere.
Branches
A branch is a copy of a repository that can be used to work on different versions of the project. This allows you to work on bug fixes or new features without affecting the project's main branch.
Commits
A commit is a snapshot of the code in a repository. When you make a change to the code, you create a commit. This allows you to track changes to the code over time.
Pull Requests
A pull request is a request to merge changes from one branch into another. This is a great way to collaborate on projects with others.
How to use GitHub
If you’re new to GitHub, here are a few steps to get you started:
- Create a GitHub Account
The first step is to create a GitHub account. You can do this for free
2. Create a repository
Once you have an account, you can create a repository. This is where you will store your code.
Go to Repositories >> New >> Create Repository
3. Link the local and remote repositories together
You can create a new project directory (Not a git repository yet) and connect it with the newly created repository using the below commands in git bash (You need to download git bash CLI for this)
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin <<Your repository URL here>>
git push -u origin main
simply copy and paste the above command and do the necessary changes
For existing repositories, you can use the below command on git bash
git remote add origin <<Your repository URL here>>
git branch -M main
git push -u origin main
Here is the sample screenshot using git bash,
After hitting enter your git bash looks like below
4. Add files to your repository
You can add files to your repository by using the “git add .” command. (dot will represent all files)
note that this command will add all the files to the git repository
git add .
5. Commit your changes
Once you have made changes to your code, you need to commit them. This will save your changes to the repository.
git commit -m "initial commit"
note that you can use any message according to your changes inside “ ”
6. Push your changes to the cloud
Once you have committed your changes, you need to push them to the cloud. This will make them available to others.
git push
As a beginner, you must remember the above three basic commands when you are using GitHub.
git add .
git commit -m "initial commit"
git push
In conclusion, GitHub is a powerful tool for software development. It can help you collaborate with others, track changes to code, and host your code in the cloud. If you’re a developer, I encourage you to check out GitHub.
Follow me on GitHub: https://github.com/ChillBroh