Mark As Completed Discussion

What is Git?

In the past decades, software engineering started to become more complex than ever, requiring larger project structures, and more collaborators on the same project. These advancements in technology and software development showed an increased need of a version control system. This type of system is responsible for changes tracking in software projects, and other types of documents, and thus allows multiple collaborators to work on the same project.

Git is a type of version control system, and it is currenly the most widely used one across the globe. It was created in 2005 by the creator of the Linux kernel, Linus Torvalds. Today it is an open source project, and works on a wide range of environments and operating systems.

How it works?

Git is available to download and be used on any OS, usually from the command line, or sometimes integrated as an extension in some IDE, which in the background uses command line as well. It offers a variety of commands, to do anything you can imagine to manage the versions of your projects, and simplify the workflow of your team.

For example, these are the most common steps you should consider in working with Git as a version control system for your project:

  1. Create a project (often called "repository") with a git hosting tool (like Github for example)
  2. Copy (clone) the repository to your local machine
  3. "Pull" someone else's changes to your local machine
  4. Create a "branch" (new version of the project, on which you will apply your changes), make the change, and then commit it
  5. Open a "pull request" (propose changes to the main branch), which then your teammates can review and approve
  6. "Merge" your branch to the main branch your content.

    What is Git and How Does It Work?

In this tutorial, we are going to walk you through the most common and important git commands, to get you started on the right track!

Initializing and cloning a repository

In order to use git with your project, you first need to either create your own repository, or clone an already existing one, which is uploaded on some git hosting tool.

SNIPPET
1$ git init algoDailyProject
2Initialized empty Git repository in /Users/test/algoDailyProject/.git/

This will initialize a new repository with the given name on your local machine, on the path provided.

SNIPPET
1$ git clone https://github.com/algoDaily/testRepo.git
2Cloning into 'testRepo'...
3remote: Counting objects: 94, done.
4remote: Total 94 (delta 0), reused 0 (delta 0), pack-reused 94
5Unpacking objects: 100% (94/94), done.
6Checking connectivity... done.

This command as shown, clones an already existing repository on the provided GitHub link, onto your local machine. It initializes a git repo, and also stores all the files from the project on a given location on your machine.

Working with branches

Branches are basically a copy of your project, where you make your changes. When you work on your newly opened branch, those changes stay there, until merged on the 'main' branch. Usually, each team establishes its own branching strategy for easier management, but the most common and simple one consists of: 1. Having a 'main' branch, that holds the production version 2. A 'develop' (or 'dev') branch, that has the beta version 3. A 'release' branch, that transfers the changes from the develop branch, to the main 4. And 'feature' branches, that are used for ongoing development that usually are followed by the name of the change (e.g. feature/add-a-subscribe-button)

What is Git and How Does It Work?