๐ From VCS to Git
In the last post, we explored Version Control System and their types โ CVCS and DVCS. Now, letโs zoom into the most popular DVCS tool in the world: Git โ and see how it powers modern development.
๐ What is Git?
Git is open source Distributed Version Control Sytem which allows developers
- Track changes in code over time
- Collaborate seamlessly with teammates
- Create branches for experimental study
- Roll back to previous versions when things goes wrong
โThink of Git as your projects time machine - but smarter, faster and made for team work
๐ฏ Core Components Git and LVC worflow
The Git workflow is a step-by-step process that defines how changes in a project move from your local machine to a shared, remote repository like GitHub. Mastering this flow helps you collaborate smoothly and manage versions efficiently.
This post explains about Git basics and how the files are committed locally
The core components of LVC worflow are: Working Directory, Staging Area, Local Repository. Understanding how files move through these stages are essential.
The diagram above outlines the LVC process. Now, letโs explore each stage and see how your local project files eventually become committed, shared history.
๐ Working Directory
This is the local folder on your computer where you edit and work on your project files
git init
command - Intializes a Git repository- The Git starts tracking the specified folder as a Git project- in other words, your plain folder(working directory) is converted into .Git project
- Creates a hidden .git. folder in the working directory
- This .git/ folder contains everything that Git needs to track your project (eg. commit, branch, logs etc)
- Your working directory stays the same, but now Git is watching for changes
๐๏ธ Staging Area
The staging area (index) is like a holding zone- where Git gathers all the changes that you want to commit
git add
command - moves the changes from working directory to the staging areagit add filename
- Adds a specific file to the staging areagit add .
- Adds all the modified files in the folder
๐ Local Repository
The local repository is the .git directory- which is the Gitโs repository storage
git commit
command - the changes from the staging area are permanently stored in the repository- The repository is located inside the hidden .git/ folder- the one created by
git init
- The .git directory contains all the commits, project history, branches, logs etc
- The repository is located inside the hidden .git/ folder- the one created by
๐กExample Snapshot: From init to commit in LVC
The snapshot below provides a practical example of how to create a new directory, initialize a Git repository, and set up local version control. It will walk you through the essential steps, including adding files to the staging area, committing changes, and managing version history on your local machine. By following along, youโll gain hands-on experience in using Git for efficient source code management.
๐ง TechNuggetz - Did you Know?
โ Git was built by Linus Torvalds - Founder of Linus in just 2 weeks in 2005 - Iconic!
โ๏ธ Git knows everything locally, it dosenโt need internet to track changes - from version history, staging and committing - everithing happens in your local machine.
โ Made a mistake?
git checkout -- filename
- restores a file to its last committed state๐๏ธ Track only what matters! Use a
.gitignore
file to prevent sensitive data (like passwords, logs, or config files) from slipping into your commits. A cleaner repo is a safer repo!๐ช Autosave magic! Use
git stash
to save your work-in-progress without a commit. Come back later withgit stash pop
and pick up right where you left off!
Continue.. ๐ To push your Git project to Remote repository like GitHub Part-2:Remote-repository
Happy Learning!