Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
States of a File in Git Working Directory
Next article icon

States of a File in Git Working Directory

Last Updated : 07 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Git is a powerful version control system that helps developers track changes in their code over time. Understanding the different states a file can be in within the Git working directory is important for effectively managing and organizing your project. This article will explore the various states of a file in Git, explaining what each state means and how it impacts your workflow.

The Git Workflow

Before diving into the states of a file, it's important to understand the basic Git workflow, which consists of three main areas:

  1. Working Directory: The current state of your project files.
  2. Staging Area (Index): A place where you can group changes before committing them.
  3. Repository (HEAD): The history of your project, including all committed changes.

States of Gile in Git Working Directory

1. Untracked state

Untracked files are any files in the working directory that were not in the last snapshot and are not in the staging area. Whenever a new file is added in the working directory which doesn't exist before, it is considered as an untracked file. This is because Git sees this as a file that didn’t have in the previous snapshot(commit). Let's see this with an example, suppose we add new file example.html in our repository and run git status command to see the status of the file. It shows a list of untracked files which include example.html file.

geeksforgeeksuntracked-file
Untracked State in Git

2. Tracked state

Tracked files are files that were in the last snapshot. These are files that Git knows about. Each track file can be in one of three sub-states, modified, staged, or committed.

3. Modified State

A file in the modified state means that changes have been made to it that haven't committed yet. The changes could be adding, modifying, or deleting the contents of the file. These files will be included in the next commit but will be included in their respective new form. Let's modify our tracked example.html file and run the git status command.

geeksforgeeksmodified-(1)
Modified States in Git

4. Staging State

A file in the staging state means either it is not present in the last commit (e.g. newly created files) or it is “modified” file that user tells git to include in the next commit. Files are added to the staging state using git add command. Two types of files can be added to a staging state: untracked or modified. Let's stage our untracked example.html file and run the git status command.

geeksforgeeksuntracked-staged
Staging State

Now, let's stage our modified tracked example.html file and run the git status command.

geeksforgeeksmodified-staged
Modified Tracked file

5. Committed State

A file in the committed state means that the changes made to it are safely stored in a snapshot in the Git directory. A file is committed using git commit command.This command creates a new snapshot in the Git directory and shows us some stats for the change made. Let's commit the changes we made in our example.html file.

geeksforgeekscommitted-(1)
Git Commit

Next Article
States of a File in Git Working Directory

R

rimjhim_25
Improve
Article Tags :
  • Web Technologies
  • Git

Similar Reads

    Saving a File in Git
    Git allows you to track changes, collaborate with others, and manage codebase efficiently. One of the fundamental tasks when working with Git is saving files, a process that involves several steps, including adding files to the staging area and committing them to the repository. In this article, we
    2 min read
    How to Fix "git ignore" Not Working Error?
    The .gitignore file in Git, allows you to specify files and directories that should be ignored by Git. However, there are some cases where .gitignore might not work as expected, causing frustration among developers. This article will guide you through the common reasons why .gitignore might not be w
    4 min read
    How to Undo Working Copy Modifications of One File in Git?
    When working with Git, it's common to make changes to files that you might later want to discard. Whether it's a file you edited by mistake or a temporary change you no longer need, Git makes it easy to undo modifications to a specific file in your working copy. In this article, we will discuss how
    3 min read
    How to Ignore Folders and Directories in Git with .gitignore?
    Git is a powerful and widely-used version control system that allows developers to track changes in their codebase, collaborate seamlessly, and maintain a robust history of their projects. It was created by Linus Torvalds in 2005, Git has become widely accepted for version control in the software de
    4 min read
    How to Remove Directory From a Git Repository?
    Managing files and directories within a Git repository is a common task, especially when you need to clean up or reorganize your project's structure. Removing a directory from a Git repository involves several steps to ensure that the change is tracked and applied correctly. In this article, we will
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences