A BEGINNER'S GUIDE TO GIT

Published: (January 18, 2026 at 03:59 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

Git is a free, open‑source version control system that developers and analysts use for tracking changes, collaborating, and managing project history efficiently. It allows you to work offline and merge your work seamlessly.

Before getting started with Git, configure your identity:

git config --global user.name "nashipae"
git config --global user.email "nashipaentungani@gmail.com"

Git Workflow

A file goes through three stages in Git:

  1. Working directory – where you edit files.
  2. Staging area – a loading dock for changes you want to save (almost final).
  3. Repository – the permanent storage area for your project.

Essential Commands

Starting a Project

  • Initialize a new repository

    git init
  • Clone an existing repository

    git clone 

Checking Status and Tracking Changes

  • Show the current status

    git status
  • View detailed changes

    git diff
  • Stage specific files

    git add 
  • Stage all changes

    git add .
  • Unstage a file

    git restore --staged 
  • Commit staged changes

    git commit -m "Your commit message"
  • View commit history

    git log

Working with Remotes

  • Add a remote repository

    git remote add origin 
  • Push to the remote (first time)

    git push -u origin main
  • Push subsequent changes

    git push origin main
  • Pull changes from the remote

    git pull origin main

History, Comparison, and Resetting

  • Compact log view

    git log --oneline
  • Show who last modified each line of a file

    git blame 
  • Compare two commits

    git diff  
  • Reset the current HEAD

    # Soft reset (keeps changes staged)
    git reset --soft HEAD~1
    
    # Mixed reset (unstages changes but keeps them in working directory)
    git reset --mixed HEAD~1
    
    # Hard reset (discards all changes)
    git reset --hard HEAD~1
Back to Blog

Related posts

Read more »

A NEWBIE'S GUIDE TO GIT(gitbash).

markdown !Githttps://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com...