From Messy Code to Clean Projects: Git Basics That Keep You on Track
By Arjun Mathur
Updated on Jul 16, 2025 | 10 min read | 7.77K+ views
Share:
For working professionals
For fresh graduates
More
By Arjun Mathur
Updated on Jul 16, 2025 | 10 min read | 7.77K+ views
Share:
Latest Update: Git 2.50.0 was released on July 1, 2025. This version includes the newest features, bug fixes, and security patches. Users are encouraged to update to this version for optimal performance and security. |
Git is a powerful version control system that allows developers to track changes, collaborate seamlessly, and manage code across projects with precision and reliability. From basic commands like init, add, commit, and push to more advanced workflows involving branching and merging, Git is essential for modern software development.
Understanding Git basics is key to building, maintaining, and scaling real-world applications in collaborative environments.
In this blog, you’ll explore the fundamental concepts and commands of Git with clear, practical examples to help you get started with confidence.
Looking to sharpen your software development workflow further? Explore upGrad’s Software Engineering courses, packed with real-world projects and expert mentorship to help you learn tools like Git, GitHub, CI/CD, and beyond. Enroll today!
Git is a version-control system used to track changes in computer files and coordinate work among multiple people. It is a Distributed Version Control System, meaning it doesn't rely on a central server.
Instead, each user clones a copy of a repository (a collection of files), and that clone includes the full history of the project on their hard drive. The original repository can be stored on a self-hosted server or a third-party hosting service, such as GitHub.
Example:
Imagine you're working on a JavaScript application. On Monday, you wrote a basic function to fetch data from an API. On Tuesday, you optimized that function for performance. On Wednesday, you added error handling.
With Git, you can view and switch between each of these versions of your code, whether it's the basic version, the optimized one or the one with error handling. This is the power of the git basics. You can easily roll back to a previous implementation if the latest change breaks something or doesn’t perform well. It’s like bookmarking every milestone in your development process and jumping to any of them whenever you need to.
Tired of losing track of code changes or overwriting someone else’s work? Learning the git basics fixes that. Here are some related courses that can help you sharpen your Git skills and grow as a developer.
Let’s break down the core Git concepts that form the foundation of the Git workflow.
Understanding Git Workflow
To effectively use Git, you must understand its core components. Git basics revolve around the Working Directory, Staging Area, Local Repository, and Remote Repository.
A file in your Working Directory can be in three states:
Now that you’re familiar with the core concepts, let’s simplify the Git basics so they feel less intimidating and more actionable.
Git helps you manage code changes, track versions, and collaborate with others more effectively. Whether you're working solo or with a team, these git basics will save you time, prevent mistakes, and help you work more confidently.
Here’s a quick guide to all the essential Git commands:
Command |
Purpose |
git config | Set up your identity (name and email) |
git init | Initialize a new Git repository |
git add . / git add <file> | Stage files for committing |
git commit -m "message" | Commit staged changes with a message |
git status | Check the status of your working directory and staging area |
git remote add origin <url> | Connect your local repo to a remote GitHub repository |
git push -u origin master | Push commits to GitHub |
git pull origin master | Pull the latest changes from GitHub |
git log | View commit history |
git diff | View unstaged changes |
git checkout -- <file> | Revert a specific file to last committed version |
git reset HEAD~1 | Undo the last commit |
git clone <repo-url> | Download (clone) an existing repo from GitHub |
git fetch + git merge | Manually pull and merge changes |
.gitignore | Tell Git which files to ignore |
Also Read: How to Use GitHub: A Beginner's Guide to Getting Started and Exploring Its Benefits in 2025
Now, let’s go through each of these git basics practically:
1. Create a Git Repository
Before tracking changes, you need to turn your project folder into a Git repository. This initializes Git, allowing you to start versioning files.
git init
Now, your directory is under Git’s control. You can open the README.md file and describe your project there.
2. Add Files to the Staging Area
To include files in your next commit, you need to move them into the staging area. This step tells Git exactly which changes you want to save. Staging is like preparing your changes before taking a snapshot. Git won’t include anything in the commit unless it has been staged. This gives you control to commit only what matters, whether that's everything you changed or just one specific file.
git add .
Or stage a specific file like this:
git add README.md
Ready to deepen your JavaScript skills? Learn core programming concepts in JavaScript and push your first project to GitHub using Git basics. upGrad’s free Advanced JavaScript course walks you through scopes, async programming, modules, and more to help you grow as a developer.
Also Read: JavaScript Free Online Course With Certification
3. Check What’s Staged
Use this to see the status of your working directory and what's staged for commit. It shows which files are modified, added, or untracked.
git status
4. Commit Your Changes
A commit is like saving a snapshot of your project's current state. It takes all the files you've staged and locks them into a version that Git can track. Once committed, your changes become a permanent part of the Git timeline. If needed, you (or your team) can roll back, compare, or review this commit later. This is essential for tracking progress, debugging issues, or collaborating with others.
git commit -m "First commit"
Also Read: Top 10 Cloud Computing Online Courses & Certifications [For Students & Working Professionals]
5. Undo the Last Commit (If Needed)
This command rolls back the most recent commit without deleting your actual code changes. It simply removes the commit from the project history and reverts the changes to the staging area. That way, you can edit, fix, or restage files before committing again. It's handy when you've committed too early or forgotten to include something important.
git reset HEAD~1
6. Add a Remote Origin and Push to GitHub
Setting a remote origin connects your local repository to a remote one, typically on GitHub. It acts as a bridge that lets you push your local commits to the cloud, making your work accessible from anywhere and shareable with your team. Once the origin is set, you can easily sync changes, collaborate across branches, and back up your project remotely.
git remote add origin <remote_repository_URL>
git remote -v
git push -u origin master
7. View Changes Before Staging
If you made edits but haven’t staged them yet, use this to see what changed line by line. It helps avoid committing unintended modifications.
git diff
8. Revert to the Last Committed Version
Reverting to the last committed version allows you to discard any local changes and restore your files to their state at the time of the last commit. This is especially helpful when something breaks, or you need a clean slate. You can either reset all files or target a specific one, making it easy to recover from mistakes and continue working with confidence.
For All Files:
git checkout .
Single file:
git checkout -- <filename>
9. View Commit History
Viewing the commit history allows you to track everything that has happened in your project over time. It shows a chronological list of all past commits, including their messages, authors, and timestamps. This helps you and your team understand how the code evolved, spot when specific changes were made, and debug or revert if something breaks.
git log
10. Clone an Existing Repository
Cloning an existing repository is like copying the full blueprint of a project onto your local machine. It provides you with the entire codebase, including its version history, allowing you to explore, modify, or contribute without affecting the original source. Once cloned, you can work locally, make changes, and later push updates or submit pull requests.
git clone <remote_repository_URL>
Example:
git clone https://github.com/Gothamv/MuskCult
11. Pushing Changes as a Contributor
If you want to contribute to a project on GitHub, there are two common approaches. This gives you direct write access to the repository. Second, by forking the repository to your own GitHub account. You can then make changes and submit a pull request. This lets the project maintainer review and merge your contributions. This is the standard process used in open-source collaboration.
Here’s how to push your changes after making commits locally:
git push origin <your branch name>
Also Read: Top Open Source Projects for Beginners
12. Collaborating with Others
Collaborating with others means keeping your local project in sync with the latest changes pushed by your teammates. When others update the shared repository, you’ll need to pull those updates into your local version to avoid conflicts, stay aligned with the current codebase, and ensure smooth teamwork.
This process helps you stay up to date, review recent contributions, and continue building without overwriting or missing anyone’s work.
git pull origin master
13. Git Fetch
git fetch differs from git pull because it only downloads changes without affecting your current code, whereas git pull updates your codebase immediately by merging those changes.
# Download changes from the remote, no merge
git fetch
14. Git Merge
git merge lets you take the changes from one branch and integrate them into another. It combines the histories of both branches without losing any work, making it ideal for feature integration or syncing updates. If there are conflicts between branches, Git will prompt you to resolve them before completing the merge.
# Merge changes from another branch into the current one
git merge <branch_name>
15. .gitignore: Keep Unwanted Files Out
The .gitignore file allows you to specify which files or directories Git should skip. This keeps your repo clean from temporary or environment-specific files.
touch .gitignore
Example .gitignore patterns:
*.DS_Store
__pycache__/
node_modules/
build/
Subscribe to upGrad's Newsletter
Join thousands of learners who receive useful tips
Git basics help you manage your code with confidence. From initializing repositories and staging files to committing changes and collaborating on GitHub, these tools form the backbone of modern software development.
To get comfortable with Git, practice tracking changes, resolving conflicts, and collaborating across branches, just like in real projects.
Learning Git is easier with real projects. upGrad’s hands-on courses offer mentorship, practical assignments, and placement support to boost your Git skills and confidence. Here are some additional courses that can boost your development:
Not sure how Git basics are applied in practical projects? Connect with upGrad’s expert counselors or drop by your nearest upGrad offline center to discover a personalized learning path aligned with your goals.
Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.
Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.
Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.
References Link:
https://git-scm.com/downloads/win
57 articles published
Arjun Mathur is Program Marketing Manager for the Software Development, bringing over 5+ years of experience in ed‑tech and growth marketing. A B.Tech in Computer Engineering from IIT Delhi, he specia...
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources