⬅ Previous Topic
Code Reusability and DRY PrincipleNext Topic ⮕
Modular Code and Project Organization⬅ Previous Topic
Code Reusability and DRY PrincipleNext Topic ⮕
Modular Code and Project OrganizationVersion control is a system that records changes to files over time so that you can recall specific versions later. It is essential for collaborative software development and also extremely useful for solo developers to track and manage changes.
Git is the most popular distributed version control system. It is fast, reliable, and widely used by developers worldwide. Git enables local development, branching, merging, and collaboration on remote repositories.
# For Windows/macOS/Linux
# Visit https://git-scm.com/ and download the appropriate installer
git init
This creates a hidden .git
folder in your current directory, marking it as a Git repository.
git add myfile.txt
This stages the specified file to be committed.
git commit -m "Initial commit with myfile.txt"
This records the snapshot of your staged files.
git log
commit 6a1f9d9c7a... Author: Your Name Date: Fri May 9 10:00:00 2025 +0530 Initial commit with myfile.txt
START
INIT project with 'git init'
CREATE or MODIFY files
STAGE files with 'git add'
COMMIT with message
REPEAT on changes
END
A: The change stays in your working directory. You can use git status
to see uncommitted changes.
A: Yes. Git provides commands like git checkout
, git reset
, and git revert
to manage changes.
A: No, Git works locally. You only need internet when working with remote repositories like GitHub.
Branches help you work on new features without affecting the main codebase.
git branch feature-x
git checkout feature-x
Once your work is complete, merge it into the main branch.
git checkout main
git merge feature-x
git remote add origin https://github.com/your/repo.git
git push -u origin main
This pushes your local commits to a remote repository for backup or collaboration.
init
, add
, commit
, log
, branch
, merge
, push
Create a simple pseudocode project (e.g., a calculator), track changes using Git as you evolve your logic from basic operations to advanced ones like recursion.
Tip: Always commit small logical changes with meaningful messages. This makes history cleaner and easier to navigate.
⬅ Previous Topic
Code Reusability and DRY PrincipleNext Topic ⮕
Modular Code and Project OrganizationYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.