← Back to Articles         
.gitignore and .git

.gitignore and .git

Published on 03 Oct 2026     2 min read Git & GitHub
Git Fundamentals

1. What is .gitignore?

.gitignore is a file used to tell Git which files or folders should not be tracked.

Common examples:

bin/
obj/
.vs/
*.log
.env

Why do we use it?

We normally exclude:

  • Build files (bin/, obj/)
  • IDE-specific files (.vs/)
  • Log/temp files
  • Environment/config files containing secrets

.gitignore generally affects untracked files. If a file is already tracked, simply adding it to .gitignore does not stop tracking it.

Interview Answer

.gitignore specifies files and folders that Git should ignore and not track. We commonly use it for build outputs, temporary files, IDE files, and sensitive configuration files.


2. What is the .git Folder?

The .git folder is a hidden folder that contains Git's internal repository data.

It is created when we run:

git init

It stores information such as:

  • Commits and objects
  • Branches and references
  • HEAD
  • Repository configuration
  • Staging/index information
MyProject/
├── Program.cs
├── .gitignore
└── .git/       ← Git repository data

Important

Do not manually modify or delete .git.

If you delete .git, the project files remain, but that folder is no longer a Git repository and its local Git history/metadata is lost.

Interview Answer

The .git folder contains the internal metadata and history of a Git repository, including commits, branches, HEAD, configuration, and staging information.


3. What is the Basic Git Workflow?

The basic Git workflow is:

Working Directory
      ↓ git add
Staging Area
      ↓ git commit
Local Repository
      ↓ git push
Remote Repository

Basic Commands

git status
git add .
git commit -m "Added login feature"
git push origin main
  • git status → Check changes
  • git add → Move changes to staging
  • git commit → Save changes locally
  • git push → Send commits to remote repository

In a team, you will usually pull/fetch the latest changes and work on a feature branch rather than pushing directly to main.

Interview Answer

The basic Git workflow is to modify files in the working directory, stage them using git add, save them to the local repository using git commit, and finally send the commits to the remote repository using git push.

← Back to Articles