Day 63 – Git Reset & Remote:

Today, I learned how to undo changes with git reset and how to work with remote repositories in Git.
These two concepts are essential for keeping your project history clean and collaborating with others.


🔹 What is git reset?

git reset is a command that lets you move the current branch’s HEAD to a specific commit, effectively undoing commits.

Three Modes of Reset

  1. Soft Reset – Keeps your changes staged

     git reset --soft <commit-id>
    

    ✅ Use when you want to rewrite commit history but keep changes ready for recommitting.

  2. Mixed Reset (default) – Keeps changes in the working directory but unstaged

     git reset <commit-id>
    

    ✅ Use when you want to unstage changes and edit before recommitting.

  3. Hard Reset – Discards all changes

     git reset --hard <commit-id>
    

    ⚠️ Be careful! This permanently removes changes.


🔹 How Reset Works Internally

Think of Git as having three areas:

  1. HEAD – Points to your current commit

  2. Index – The staging area

  3. Working Directory – Your files

  • --soft → Moves HEAD only

  • --mixed → Moves HEAD + Index

  • --hard → Moves HEAD + Index + Working Directory


🔹 Working with Remote

A remote is a version of your repository hosted somewhere else (e.g., GitHub, GitLab, Bitbucket).

Common Commands

  • Add a remote

      git remote add origin https://github.com/user/repo.git
    
  • View remotes

      git remote -v
    
  • Push changes

      git push origin main
    
  • Fetch changes without merging

      git fetch origin
    
  • Pull changes (fetch + merge)

      git pull origin main
    

🔹 Real-World Example

Let’s say you pushed a commit to GitHub by mistake and want to reset it:

git reset --hard HEAD~1   # Remove last commit locally
git push origin main --force  # Update remote to match

⚠️ Only force-push if you are sure—it rewrites history and can affect others.


Takeaway:

  • Reset controls your commit history locally

  • Remote helps you collaborate and share your work online

  • Combining them with care keeps your Git history clean and teamwork smooth

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir