Skip to main content

Command Palette

Search for a command to run...

Git Basics for Beginners: Key Commands You Need to Know

Published
2 min read

What is Git?

Gate is a version control system which means it helps devs track their changes in their code.

Git is a distributed version control system which means

  • Every dev has complete copy of the project

  • Changes can be tracked without Internet

  • Work can continue even if central server is down

Why is Git Used?

Before Git devs used folders like final, final_v2, final_latest

This caused problems

  • Code got overwritten

  • No history of changes

  • Difficult to collaborate

  • No undo option if something broke

Git solved all this problem by

  • Tracking every change

  • Allowing teams to work together

  • Letting dev go back Previous version

  • Making collaboration safe and easy

Git Basics and Core Technologies

  1. Repository(Repo)

    A repository is a project folder that is tracked by git. Once a folder becomes a git repo, it starts monitoring all the files inside it.

  2. Commit

    A commit is a saved snapshot of our code.

    Every commit has

    a. A unique id

    b. Author name

    c. Date and time

    d. A commit message is explaining What changes were made in this code

  3. Branch

    A branches separate line of development. Main or master is the default branch. We Create new branches to work on different features without disturbing the main flow.

  4. Head

    It points to the current commit that we are working on

Common Git Commands with Example

  1. git init

    This command creates a hidden folder named .git and starts monitoring the project.

  2. git status

    Show the current status of files. It tells us which files are new, which files are modified and which our files are staged.

  3. git add <filename>

    Staging a file for commit

  4. git add .

    Stage all changed and untracked files for commit

  5. git commit -m ”commit message”

    Save all stage changes with a commit message explaining what we did.

  6. git log

    Shows are commit history. We can see our commit IDs, author Date and commit messages.

Closing Statement

Git may feel confusing at first. But we learned what git is and why it is widely using software development. We also covered git concepts like repository, commit branches and head. And explored git commands used in day to day work.