Git vs GitHub: Key Differences

Author: Tatyana Milkina

In this section, you'll learn what Git and GitHub are, their key differences, and get familiar with essential Git concepts and commands.

1. GitHub vs Git — What’s the Difference?

Git is a distributed version control system. It allows you to track code changes, work with branches, collaborate with other developers, roll back changes, and work offline.

GitHub is a web service for hosting Git repositories and managing collaborative development. It enhances Git with a user-friendly interface, pull requests, issue tracking, discussions, and team collaboration tools.

GitHub’s motto is Social Coding. It’s not just a code storage — it's a powerful platform used by millions of developers for both open-source and private projects.

2. File States in Git Working Directory

  1. Tracked files — files that were part of the last project snapshot or are staged for the next commit. They can be unmodified, modified, or newly added.
  2. Untracked files — any files in your working directory that are not yet part of version control or staged for commit.

3. Essential Git Commands

  1. git init — initializes a new local repository.
  2. git add — stages files for the next commit (adds them to the index).
  3. git commit — saves a snapshot of the project in the repository. Git stores the current state of each file and creates a reference to this snapshot. If a file hasn’t changed, Git links to the previous version instead of duplicating it.
  4. git fetch — connects to a remote repository and retrieves new data not yet in your local repo. It does not merge changes — you must merge them manually when ready.
  5. git push — shares your changes by uploading commits to the remote repository. This works only if no one else has pushed changes since you last pulled. If they have, you must pull and merge before pushing.
  6. git pull — automatically fetches and merges changes from a remote branch into your current local branch. It combines fetch and merge in one step and is often used to sync with the remote repository.

4. Tags

Tags allow you to mark specific points in history as important — typically used for marking version releases such as v1.0, v2.0, etc.

5. Branching

Branching lets you create isolated lines of development for new features or bug fixes. The default branch in Git is called main or master. Git saves your project as snapshots, and each branch is simply a lightweight pointer to a commit.

6. Working with Remote Repositories

A remote repository is a version of your project stored online (e.g., on GitHub). You interact with it using commands like git fetch, git pull, and git push.

You can have multiple remotes, each with read-only or read/write permissions depending on your access.

7. Fork — Creating a Copy of a Repository on GitHub

If you want to contribute to a public project you don’t have write access to, you can use the fork feature. It creates a personal copy of the repository under your GitHub account.

You can then make changes in your forked repo and submit a pull request to the original repository. Forking is a standard practice in open-source collaboration. GitHub automatically tracks the relationship between your fork and the source repo.

Курс 'Java для начинающих' на Udemy Курс 'Java для начинающих' на Udemy
Read also:
Comments