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
.gitignoregenerally affects untracked files. If a file is already tracked, simply adding it to.gitignoredoes not stop tracking it.
Interview Answer
.gitignorespecifies 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
.gitfolder 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 changesgit add→ Move changes to staginggit commit→ Save changes locallygit 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 usinggit commit, and finally send the commits to the remote repository usinggit push.