DEV Community

Cover image for My journey in learning git basics 🧗🏻‍♀️
Denise
Denise

Posted on

My journey in learning git basics 🧗🏻‍♀️

Git is the most popular version control tool. If you are currently working as a software developer, you probably use it on a daily basis, and if you are looking for a new job, you will definitely need to know it to work with your team.

As a beginner in the web development world, I wrote this article both to help you and me clarify some basic git concepts.

Here's a simple overview. 😊

Short introduction

What is git?

Git is a version control system (there are several, git is just the most popular) that helps people to collaborate on a project.

A version control system is a software that tracks all the changes that have been made to the source code of a project.

Git is able to track not only which change has been made (e.g. someone changed the button’s color on a specific file), but also who made it and when.

Why git is so useful?

Git is useful because it allows everyone to work on a project without the fear of compromising the stable version of its code.

You can work on a specific issue or bug, roll back to previous changes, and have multiple versions of the same codebase.

Here’s an example:

Let’s suppose you want to change your application’s theme, but you do not want to touch the source code. To do that, you can create a new branch (imagine it as a new story of the whole project), change the theme, and then merge (apply) the changes you made on that branch on the stable code.

What is a git repository?

A git repository is the .git folder inside your current folder. It tracks all the changes you make within the project’s files (e.g. all the information about the commits, in which branch you are etc).

Basic commands

git init

Create a .git repository. You have to run this command in order to use git.

git clone

Clone (download) an existing repository from a git server (e.g. GitHub), and put it on your local machine.

git add

Add a file to the staging area.
The staging area is the place where a modified file stays before it’s committed.

Here's a scenario:

  • You modify a file called message.txt (this file is untracked, a.k.a git is not aware of it);

  • You add message.txt to the staging area;

  • You commit, so you "move" message.txt and all the other files that are tracked from the staging area to the commit history.

git commit

Take all the changes and “save” them by giving a unique identifier (the identifier is created by an algorithm called SHA-1)

git status

Tells you about the status of your current repo:

  • In which branch you are;

  • Changes that are not staged yet (you modified a file but you did not add it to the staging area);

  • Changes that are not committed yet (you added a file to the staging area, but you did not commit yet);

  • Changes are staged and committed.

git log

Tells you about the commit’s history:

  • Commit’s identifier (e.g. 00b12a46b9cf97324a59266d2721d41eb98621ff);

  • Commit’s author (e.g. magicmario);

  • Commit’s date (e.g. Tue Mar 16 18:25:35 2021 +0100);

  • Commit’s description (e.g. change: button color on main.html).

git branch

Give you a list of all the branches in your repository. It is used also to create and delete a specific branch.

A branch is an independent development history and is usually used to develop new features or work on bugs separately.

git merge

Join two branches (development histories) together and create a commit for the updated changes.

git fetch

Download all the latest data from the remote repository to your local repo. Important: it does not put these data into your files.

git pull

Retrieve (fetch) information from the remote repository and apply (merge) these to your local branch. Basically is the combination of these two commands: git fetch and git merge

git push

Upload your work to the remote repository (online).

Source: the internet. 🌌

Any feedback is welcomed!

Thank you (:

Top comments (2)

Collapse
 
debrakayeelliott profile image
Debra-Kaye Elliott

I'm learning Git right now. Thanks for sharing 👍🏾.

Collapse
 
denimartn profile image
Denise

I hope it will help you 😊