What is git? An easy introduction

what is git with answers

Git can seem a bit intimidating for someone who knows nothing about it. But knowing git is essential for anyone who codes. It’s worth spending some time learning about the basics, even if you’re new to coding. Actually, I would say the earlier you learn git the better! Having a good understanding of how git is used to control your source files will make parts of the development process much simpler for you.

In this post we’ll tell you why you need git. We’ll also go through the fundamentals of git so you can get an idea of how it works without being overwhelmed with it’s many features.

(By the way if you are curious, ‘git’ is not an acronym!)

Git is a management system for your files. In simple terms, it allows you to save snapshots of your files at any point in time. It also allows you to view differences between snapshots and revert to any saved snapshot.

trach changes with git

In software development, git is very useful as it provides a way to apply version control on snapshots of the project. Using this management system on your source files also allows you to keep track of changes you make as the project develops. Being able to view how the source files changed over time is crucial for many reasons. For example, when identifying bugs that arise when the source was changed, the ability to revert to the previous working version can help in identifying what change caused that bug.

How does git work?

Let’s start by understanding some key terms used within the git system.

git commits and branches

Repository

A group of folders and files under control of git is known as a repository (or repo for short). You can tell if a git repository exists with in a folder if you can see a ‘.git’ folder within it. All files, folders and subfolders that exist in the same location as the ‘.git’ folder is part of the repository.

Note: You will not be able to see the ‘.git’ folder if the option to show hidden files and folders is disabled in your file manager. So make sure this option is enabled if you want to see it. And a warning, do not edit the contents of the ‘.git’ folder as doing so may destroy your repository!

Commits

Snapshots of your repositories at a point in time are known as commits. The action of ‘making a commit’ saves a snapshot of your repository and labels the commit by applying a commit message. What you say in the commit message is important as it will allow you to quickly remember the state of the repository when the commit was made. Keep this in mind when making commit messages.

Branch

A branch provides a way of making a copy of the entire repository at a particular commit. When a repository is created, a branch called ‘master’ is also created as the default branch. With every commit, the master branch will follow along so it always points to the latest commit. New branches can also be created which become a way of making changes independent of other existing branches. 

Good practice encourages working from other branches and leaving the master branch clean. By creating a branch separate to master and working from that, you can make changes without affecting the main progression line of the repository.

Branching is very useful when more than one person is working on a project. Individuals can work on their own branches and later merge it onto the master branch.

What about Github?

Github and git have two separate meanings and it’s important to know the difference.

Github is an online hosting platform for your git repositories. Github is one of many git repository hosting platforms available, but is usually the go to choice for hosting open source collaboration projects.

When a repository is hosted in an online location such as on Github, it is known as a remote repository. When the repository resides on your local machine, it is a local repository. Part of the usefulness of the git management system is being able to sync up local and remote repositories.

work together github

While it’s not essential to have a remote version of your repository, it’s a good idea to have one for several reasons.

First, it’s good to have a cloud backup of your source files in case anything happens to the repository on your local machine. With most hosting platforms (Github included) providing free repository hosting for individuals, there’s no reason not to have remote copies of your repositories (well, unless you are paranoid about hackers potentially accessing your online files…).

Second, in the case when more than person is working on a project, having a central location which is accessible to everyone is essential to collaborating more effortlessly. Imagine there are three developers working on a project, each with their own snapshot of the repository. Having a location where each developer can upload updates to the project and view changes made by the others is necessary to ensure they are all aligned.

Lastly, even if you work on projects alone, having a collection of your projects hosted on an easily accessible platform is a nice way to develop a portfolio of your work. It provides a convenient way of sharing your coding projects to others as all you need to provide is a URL to the repository (as long as you enable public access to the repository). It can also be a great way to showcase your portfolio for job applications!

How do I actually start using git?

First install the git application on your PC. The following website is a good place to find installation files for your operating system: https://git-scm.com/downloads

Once installed you can play around with creating a repository, committing files, branching, and all other key features we talked about.

I would also advise creating a Github account and following their tutorial to get started in learning how to navigate around Github. Here at inspirezone we use Github as the server for managing the git repositories for our projects. So owning a Github account and knowing the basics of git is necessary if you want to contribute to projects hosted by us.

Conclusion

At the start you were curious, what is git? Hopefully you have a better understanding now and know the importance of using git to manage your source code.

Using git is central at inspirezone in managing how several people can work on a coding project in a controlled manner. Once you are familiar with git you can start contributing to projects! Check out the Dev Zone for a list of all projects you can work on right now. If you want to submit your own project idea so we can start collaborating on it, you can do so by getting in touch with us.

If you have any questions ask away in the comments below!