Understanding Git Repository
Last Updated :
11 Dec, 2025
A Git repository (or repo) is a storage space where your project’s files and their complete history of changes are kept. It allows you to track, manage, and collaborate on code over time.
- Stores all files, branches, commits, and history of a project.
- Allows version control: you can go back to any previous state of your project.
- Supports collaboration: multiple developers can work together without overwriting each other’s changes.
- Can be cloned to create copies on different machines.
Git RepositoryTypes of Git Repositories
1. Local Repository
- Stored on your own computer.
- Allows you to make changes, commit them, and review your project history without needing an internet connection.
- Example: The
.git folder inside your project contains the local repository.
2. Remote Repository
- Hosted on a server like GitHub, GitLab, or Bitbucket.
- Enables multiple developers to collaborate on the same project.
- Supports operations like
push, pull, and fetch to synchronize changes with the local repository.
Bare vs Non-Bare Repositories
| Bare Repository | Non-Bare Repository |
|---|
| Contains only the version history and Git data, no working files. | Contains working files along with the Git history. |
| Mainly used on servers for collaboration. | Used on local machines for development. |
Cannot directly edit files; only supports Git operations like push and fetch. | Files can be edited directly; supports all Git operations including commit and merge. |
Usually ends with .git extension. | Does not usually end with .git extension. |
| Acts as a central repository for multiple developers. | Acts as a local copy for development and testing. |
Initialize a Git Repository
Before you can start tracking files, you need to initialize a repository in your project folder. This is done with the git init command.
$ git init
Syntax And Usage Of `git add`
$ git add file_name
The following are the different ways to use add command:
- To add all the working area files in the current repository to the stagging Area following command is used:
$ git add .
- To add a specific list of files to the staging area.
$ git add --all
- To add all files with extension .txt of the current directory to a staging area.
$ git add *.txt
- To add all text files with .txt extension of the docs directory to staging area.
$ git add docs/*.txt
- To add all text files of a particular directory(docs) to staging area.
$ git add docs/
- To add all files in a particular directory(docs) to staging area.
$ git add “*.txt”
Moving From Staging Area To Commit Area In A Git Repository
To add text files of entire project to staging area. Committing changes from the Index Committing process is done in the staging area on the files which are added to the Index after git add command is executed. This committing process is done by the use of git commit command. This command commits the staged changes to the local repository.
Syntax And Usage Of `git commit`
$ git commit -m "Add existing file"
This commit command is used to add any of the tracked files to staging area and commit them by providing a message to remember.
Cloning And Synchronizing With Remote Repositories
Git lets users clone repositories to their local machine, creating separate copies. To sync changes with others, Git provides commands to synchronize local repositories with remote one.
Git Push And Pull Commands
Git Push
This git push command is used to push all the commits of the current repository to the tracked remote repository. This command can be used to push your repository to multiple repositories at once.
Syntax
$ git push -u origin master
To push all the contents of our local repository that belong to the master branch to the server (Global repository).
Git Pull
The git pull command updates your local repository by fetching and merging changes from the remote repository. It ensures your copy stays synchronized when others have made updates.
Syntax
$ git pull
Additional Git Commands
Git Status
It is used for checking the status of git repository, i.e., if the files are committed or not, files in staging area or untracked file.
Syntax
$ git status
Git Log
It is used to track all the changes made in the repository, providing the information on contributors and their contributions.
Syntax
$ git log
.gitignore
You may use .gitignore if you want to hide any file when uploading online. Just simply create a .gitignore file, and write all the files names you want to ignore.
Git Merge
It is used to merge two branches within the same repository. It combines the changes from one branch into another (usually merging a feature branch into the main branch) without losing history.
Syntax
$ git merge <branch-name>
Git Checkout
Git checkout is a command used to switch between branches or view a previous version of your project by moving the HEAD pointer to a different commit. It does not permanently rollback your project-it simply allows you to explore or temporarily switch to an older commit using its hash from git log.
Syntax
$ git checkout <hash-code>
To know more git commands refer this - Git cheat sheet
Also Check
What is a Git repository?
-
A cloud service for hosting databases
-
A storage space that contains your project and full history of changes
-
A backup tool used to delete project history
-
A compiler for source code
Explanation:
A Git repository stores all project files, branches, commits, and complete history, allowing developers to track, manage, and collaborate on code.
Which statement correctly describes a bare repository?
-
It contains both working files and Git history
-
It is used only on a developer’s local machine
-
It contains only Git’s version history, without working files
-
It allows direct editing of project files
Explanation:
A bare repository holds only Git metadata (no working directory). It is commonly used as a central server repo for collaboration.
Which command is used to add all modified and untracked files from the current directory to the staging area?
Explanation:
git add . stages all new, modified, and deleted files in the current directory and its subdirectories.
What is the purpose of the git commit -m "message" command?
-
To save changes directly to the remote repo
-
To move staged changes into the local repository permanently
-
-
Explanation:
git commit moves files from the staging area to the local repository, creating a snapshot with a message for future reference.
Which Git command is used to synchronize local changes with a remote repository by downloading and merging updates?
Explanation:
git pull performs fetch + merge, bringing remote updates into your local branch to keep it synchronized with the remote.
Quiz Completed Successfully
Your Score : 2/5
Accuracy : 0%
Login to View Explanation
1/5
1/5
< Previous
Next >
Explore
Git Introduction
Git Installation and Setup
All Git Commands
Most Used Git Commands
Git Branch
Git Merge
Git Tools and Integration
Git Remote Repositories
Collaborating with Git
Advanced Git Commands