Git and GitHub are at the core of open source in today’s programming world. However, there are a lot of confusing often seem about these terms, similar yet have different meanings and uses. Let’s demystify this confusion by decoding their underlying meanings.
In this article, we’ll first explain Version control
Then, we’ll dig into more about Git and GitHub.
What is version control? Essentially, it’s a system that allows you to record changes to files over time, thus, you can view specific versions of those files later on.
A version control system, or VCS, tracks the history of changes as people and teams collaborate on projects together. As the project evolves, teams can run tests, fix bugs, and contribute new code with the confidence that any version can be recovered at any time. Developers can review project history to find out:
- Which changes were made
- Who made the changes
- When were the changes made
- Why were changes needed
Git is an example of a distributed version control system (DVCS) commonly used for open source and commercial software development. DVCSs allow full access to every file, branch, and iteration of a project, and allows every user access to a full and self-contained history of all changes. Unlike once popular centralised version control systems, DVCSs like Git don’t need a constant connection to a central repository. Developers can work anywhere and collaborate asynchronously from any time zone.
Git is a commonly used Version Control System (VCS) that allows you to keep track of all the code changes. This means you can simply roll back to a previous update if a new function causes problems.
Git, on the other hand, isn't just any VCS; it's a Distributed VCS. This means that each project partner would have a record of the modifications made to their own computer. As a result, people will focus on various aspects of the project without having to connect with the website that hosts the remote version. This is extremely effective, and any modifications made to the project can be quickly merged with the remote copy.
To use Git, developers use specific commands to copy, create, change, and combine code. These commands can be executed directly from the command line or by using an application like GitHub Desktop or Git Kraken. Here are some common commands for using Git:
git initinitialises a brand new Git repository and begins tracking an existing directory. It adds a hidden sub folder within the existing directory that houses the internal data structure required for version control.
git clonecreates a local copy of a project that already exists remotely. The clone includes all the project’s files, history, and branches.
git addstages a change. Git tracks changes to a developer’s code base, but it’s necessary to stage and take a snapshot of the changes to include them in the project’s history. This command performs staging, the first part of that two-step process. Any changes that are staged will become a part of the next snapshot and a part of the project’s history. Staging and committing separately gives developers complete control over the history of their project without changing how they code and work.
git commitsaves the snapshot to the project history and completes the change-tracking process. In short, a commit functions like taking a photo. Anything that’s been staged with git add will become a part of the snapshot with git commit.
git statusshows the status of changes as untracked, modified, or staged.
git branchshows the branches being worked on locally.
git mergemerges lines of development together. This command is typically used to combine changes made on two distinct branches. For example, a developer would merge when they want to combine changes from a feature branch into the master branch for deployment.
git pullupdates the local line of development with updates from its remote counterpart. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.
git pushupdates the remote repository with any commits made locally to a branch.
Git is at the heart of GitHub, a commonly used version management tool. It allows you to host a remote version of your project, which all partners can use. Any GitHub user, not just members of your team, will add to your code (that is of course if you choose to accept the changes made).
GitHub is a social forum where you can discover open-source software and its source code.
You can work together on incredible projects and share your contributions! This is the most effective open-source framework available.
Additionally, anyone can sign up and host a public code repository for free, which makes GitHub especially popular with open-source projects.
GitHub builds collaboration directly into the development process. Work is organised into repositories, where developers can outline requirements or direction and set expectations for team members. Then, using the GitHub flow, developers simply create a branch to work on updates, commit changes to save them, open a pull request to propose and discuss changes, and merge pull requests once everyone is on the same page.
The GitHub flow is a lightweight, branch-based workflow built around core Git commands used by teams around the globe — including ours.
The GitHub flow has six steps, each with distinct benefits when implemented:
- Create a branch: Topic branches created from the canonical deployment branch (usually master) allow teams to contribute to many parallel efforts. Short-lived topic branches, in particular, keep teams focused and results in quick ships.
- Add commits: Snapshots of development efforts within a branch create safe, revertible points in the project’s history.
- Open a pull request: Pull requests publicize a project’s ongoing efforts and set the tone for a transparent development process.
- Discuss and review code: Teams participate in code reviews by commenting, testing, and reviewing open pull requests. Code review is at the core of an open and participatory culture.
- Merge: Upon clicking merge, GitHub automatically performs the equivalent of a local ‘git merge’ operation. GitHub also keeps the entire branch development history on the merged pull request.
- Deploy: Teams can choose the best release cycles or incorporate continuous integration tools and operate with the assurance that code on the deployment branch has gone through a robust workflow.
As a student, you can get access to the GitHub Student Developer Pack, which includes benefits from GitHub as well as other partners. From GitHub, students receive a free micro account with five private repositories. Learn more about the Student Developer Pack here.