DEV Community

Beverline Otiende
Beverline Otiende

Posted on

A beginners guide to Git: Version control, Tracking changes, Pushing and Pulling Code.

If you are serious about Tech, then Git is one of the non-negotiables. You've probably heard about the word Git and Github thrown around by 'Techies' and it may sound intimidating to you as a beginner.
In this article, we are going to breakdown and understand what Git is and how we can use it.
This article aims to explain:

  • What version control is
  • What git is and how it matters
  • How Git tracks changes
  • How to push and pull code

Understanding Version control
Version control is a system that tracks and records changes made to our code over time in a special database called repository.
A repository in simple terms is a project folder that Git is tracking.
Think of version control as a time machine + a collaboration tool for your code that helps us work together and track changes.
It also helps us know what changes were made to our code and by who, and if you screw something up you can easily revert your project back to an earlier state.
There are different version control system but Git is the most common one.

What is Git and why it matters
Git is the most popular version control system in the world. This is mainly because it is free, open source, super fast and scalable.
The main difference between Git and Github is that Git is a tool installed in your computer and Github is an online platform that stores Git repositories.
To be able to use Git you have to install it in your computer using the link; google for windows and for mac and Linux install via the official site.

To check the version of git installed in you computer yo run the code;

git --version
Enter fullscreen mode Exit fullscreen mode

Git runs locally on your computer and;

  • Tracks every change you make to your files
  • Knows who made each change and when
  • Allows you to save snapshots of your project

How Git tracks changes

Git generally has three main states for its files;

  1. Working directory: this is where you edit files
  2. Staging area: this is where you tell Git the changes you want to save
  3. Repository(History): this is where Git permanently stores snapshots(commits).

A commit is a snapshot of your project at a specific time and
Each commit normally has a;
-Unique ID
-Author
-Date
-Message
The commit history acts as the Git time machine and we can view it using the code;

git log
Enter fullscreen mode Exit fullscreen mode

Pushing code to GitHub(Git push)
Git push means sending your local commits to the remote repository(Github).
To push code to Github, we use the code;

git push -u origin name
Enter fullscreen mode Exit fullscreen mode

When you enter this code on your Git, your code appears on Github and is visible to other people.

Pulling code from Github(Git pull)
This is done to get the latest changes from the remote repository(Github).
The code for pulling code is;

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Git pull is very important especially when working on multiple machine, collaborating with others and when updating your local copy.

Why Git is essential for your career
If you are serious about Tech, then Git is a non-negotiable for your career.
Git mainly helps you to;

  • Collaborate with teams worldwide
  • Work safely without fear
  • Show your work to employers
  • Contribute to open source projects

When working with Git as a beginner, it is very important to;

  • Always commit often in small chunks
  • Be specific and clear with your commit messages
  • Always Git pull before starting work

In conclusion, Git may feel confusing at first, but it becomes second nature with practice. Just start small, make mistakes, learn and keep going.

Top comments (0)