Git Logo

What Is Git?

Git is a Distributed Version Control System (DVCS). It helps you track changes in your code, work with team members, and manage different versions of a project easily.


Why Git?

  • It’s widely used and trusted by developers across the world
  • Works offline and online
  • Can be easily integrated with platforms like GitHub, GitLab, or Bitbucket
  • Helps manage your source code and changes over time

Git Lifecycle: Step-by-Step


git To understand how Git works, it’s important to know the Git lifecycle. Think of it as the path your code follows before it's shared with others.



1.Working Directory

This is the folder on your computer where your project lives. You make changes to files


2. Staging Area (Index)

Once your changes are ready, you add them to the staging area. This tells Git which changes you want to include in your next commit.


3.Commit

You save a snapshot of the changes with a commit. Each commit has a unique ID and a message describing the changes.


4. Push to Remote

After committing, you can push your changes to a remote repository like GitHub, so others can see or collaborate on the project.



How Does Git Work?

  • Every time you save your work with a commit, Git records the changes and assigns a commit ID (a unique code)
  • If you edit a file again, it gets saved as a new commit, with a new ID.
  • Git keeps all versions of your code. You can go back to any version using its commit ID.
  • Commits are saved in branches. A branch is like a separate line of development.
  • The latest commit in a branch is pointed to by a pointer called HEAD.
  • The main branch (by default) is called master (or sometimes main), and it usually contains the final version of your code.