Skip to main content

Command Palette

Search for a command to run...

Problem: Messy File Versions

Published
2 min readView as Markdown

We've all been there—saving multiple versions of a file to avoid losing work:

  • script.js

  • script_v2.js

  • script_final.js

  • script_final_fixed.js

This method is chaotic and hard to manage, especially in teams. Git offers a solution as a Distributed Version Control System, allowing you to track changes, experiment safely, and collaborate efficiently.

Part 1: Understanding Git's Core

Git operates with three main areas:

  1. Working Directory: Your current workspace where files can be "Untracked" or "Modified."

  2. Staging Area: A place to select specific changes for your next commit.

  3. Repository: The .git folder storing all your project's snapshots (commits).

Part 2: Initial Setup

Introduce yourself to Git with:

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

Part 3: Essential Commands

  1. git init: Start Git in your project folder.

  2. git status: Check the state of your files.

  3. git add: Move files to the Staging Area.

  4. git commit: Save changes to the Repository with a clear message.

  5. git log: View your project's history.

Part 4: Branching

Branches allow you to work on features independently:

  • Create a Branch: git branch dark-mode

  • Switch Branches: git checkout dark-mode

  • Merge Changes: Combine branches when ready.

Part 5: Using Remotes

To back up or share your work, use remote repositories like GitHub:

  • Clone: git clone [url]

  • Push: git push origin main

  • Pull: git pull origin main

Summary Cheat Sheet

CommandActionAnalogy
git initStart Git in a folderBuying a blank diary
git statusCheck file statesChecking your to-do list
git add .Stage filesPutting items in a shopping cart
git commit -m "msg"Save changes to RepoTaking a photo of the cart
git branch [name]Create a new branchCreating a parallel timeline
git checkout [name]Switch branchesHopping between timelines
git merge [name]Combine branchesWeaving two threads together
git pushUpload to cloudUploading photos to Google Drive

Mastering Git takes time. Start with add and commit, then explore branching. Happy coding!